Zero Escape Time limit:2000/1000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 207 Accepted Submission (s): 91
Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (your may hear about E Ver17?) and developed by Chunsoft.
Stilwell is enjoying the first chapter of this series, and in this chapter digital root are an important factor.
The definition of digital root on Wikipedia:
The digital root of a non-negative integer is the digit value obtained by an iterative process of summing digits, O n each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
For example, the digital root of 65536 is 7, because 6+5+5+3+6=25 and 2+5=7.
In the game, every player has a special identifier. Maybe players has the same identifier, but they is different players. If a group of players want to get into a door numbered X (1≤x≤9), the digital root of their identifier sum must is X.
For example, players {1,2,6} can get to the door 9, but players {2,3,3} can ' t.
There is the doors, numbered A and B. Maybe a=b, but they is the different door.
And there is n players, the everyone must get into one of the these and the doors. Some players'll get into the door A, and others'll get into the door B.
For example:
Players is {1,2,6}, a=9, b=1
There is only one-to-distribute the Players:all players get into the door 9. Because There is no player to get into the door 1, the digital root limit of this door would be ignored.
Given The identifier of every player, please calculate how many kinds of methods is there, MoD 258280327.
Input the first line of the input contains a single number T, the number of test cases.
For each test case, the first line contains three integers n, A and B.
Next line contains n integers idi, describing the identifier of every player.
t≤100, n≤105,∑n≤106, 1≤a,b,idi≤9
Output-for-each-test case, output-a single-integer in A-line, the number of ways that these n players can get into These, doors.
Sample Input
4 3 9 1 1 2 6 3 9 1 2 3 3 5 2 3 1 1 1 1 1 9 9 9 1 2 3 4 5 6 7 8 9
Sample Output
1 0 10 60
Source multi-university Training Contest 8
For a root number: the sum of the numbers in all positions is the last root number. ========= so a number, either first plus or later, has no effect.
Define DP[I][J] To add a set of the number of the root to get the value of I, added to the set B has a root number obtained by the value of J
For input digital x transfer to DP[I+X][J] + = Dp[i][j], dp[i][j+x] + = Dp[i][j]
The case of adding a or adding a set of B in the final special treatment;
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace
Std
#define LL int ll mod = 258280327;
ll DP[2][10][10];
int mp[30];
int main () {for (int i = 0;i <; i++) Mp[i] = i%10 + I/10;
int t;
scanf ("%d", &t);
while (t--) {int p = 0, q = 1;
Memset (Dp,0,sizeof (DP));
Dp[p][0][0] = 1;
int a,b,n,u,v;
scanf ("%d%d%d", &n,&a,&b);
int t = 0;
while (n--) {memset (dp[q],0,sizeof (Dp[q]));
scanf ("%d", &u);
t = Mp[t+u];
for (int i = 0;i <, i++) {for (int j = 0;j <; j + +) {v = mp[i+u];
DP[Q][V][J] + = dp[p][i][j];
if (Dp[q][v][j] >= MoD) dp[q][v][j]-= mod;
v = mp[j+u];
DP[Q][I][V] + = dp[p][i][j];
if (Dp[q][i][v] >= MoD) DP[Q][I][V]-= mod;
}} swap (P,Q);
} ll ans = dp[p][a][b];
if (t = = a) ans++;
if (t = = b) ans++;
Ans%= MoD;
printf ("%i64d\n", ans);
} return 0;
}