• 应用
• 登录
• 注册

# P3123 [USACO15OPEN]贝茜说哞Bessie Goes Moo

• 83通过
• 186提交
• 题目提供者 FarmerJohn2
• 评测方式 云端评测
• 标签 动态规划,动规,dp 单调队列 递推 USACO 2015
• 难度 提高+/省选-
• 时空限制 1000ms / 128MB
• 提示：收藏到任务计划后，可在首页查看。

## 题目描述

Farmer John and Bessie the cow love to exchange math puzzles in their free time.

The last puzzle FJ gave Bessie was quite difficult and she failed to solve it.

Now she wants to get even with FJ by giving him a challenging puzzle.

Bessie gives FJ the expression $(B+E+S+S+I+E)(G+O+E+S)(M+O+O)$ , containing the

seven variables $B,E,S,I,G,O,M$ (the " $O$ " is a variable, not a zero). For each

variable, she gives FJ a list of up to 500 integer values the variable can

possibly take. She asks FJ to count the number of different ways he can assign

values to the variables so the entire expression evaluates to a multiple of 7.

Note that the answer to this problem can be too large to fit into a 32-bit

integer, so you probably want to use 64-bit integers (e.g., "long long"s in C or

C++). 七个变量B,E,S,I,G,O,M;使得(B+E+S+S+I+E)(G+O+E+S)(M+O+O)被7整除的方案有多少种.

## 输入输出格式

输入格式：

The first line of the input contains an integer $N$ . The next $N$ lines each

contain a variable and a possible value for that variable. Each variable will

appear in this list at least once and at most 500 times. No possible value will

be listed more than once for the same variable. All possible values will be in

the range $-10^5$ to $10^5$ .

输出格式：

Print a single integer, giving the number of ways FJ can assign values to

variables so the expression above evaluates to a multiple of 7.

## 输入输出样例

输入样例#1： 复制
10
B 2
E 5
S 7
I 10
O 16
M 19
B 3
G 1
I 9
M 2
输出样例#1： 复制
2

## 说明

The two possible assignments are

(B,E,S,I,G,O,M) = (2, 5, 7, 9, 1, 16, 19) -> 51,765

= (2, 5, 7, 9, 1, 16, 2 ) -> 34,510

提示
标程仅供做题后或实在无思路时参考。
请自觉、自律地使用该功能并请对自己的学习负责。
如果发现恶意抄袭标程，将按照I类违反进行处理。