2015 Multi-University Training Contest 8 hdu 5389 Zero Escape
2015-08-13 22:18
423 查看
Zero Escape
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 407 Accepted Submission(s): 190
[align=left]Problem Description[/align]
Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (you may hear about ever17?) and developed by Chunsoft.
Stilwell is enjoying the first chapter of this series, and in this chapter digital root is an important factor.
This is the definition of digital root on Wikipedia:
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on 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 two players have the same identifier, but they are 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 be X.
For example, players {1,2,6} can get into the door 9, but players {2,3,3} can't.
There is two doors, numbered A and B. Maybe A=B, but they are two different door.
And there is n players, everyone must get into one of these two doors. Some players will get into the door A, and others will get into the door B.
For example:
players are {1,2,6}, A=9, B=1
There is only one way 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 will be ignored.
Given the identifier of every player, please calculate how many kinds of methods are 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
[align=left]Output[/align]
For each test case, output a single integer in a single line, the number of ways that these n players can get into these two doors.
[align=left]Sample Input[/align]
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
[align=left]Sample Output[/align]
1
0
10
60
[align=left]Source[/align]
2015 Multi-University Training Contest 8
解题:动态规划
dp[i][j]表示当前考察了第i个且余数为j的方案数
\[dp[i]][j] += dp[i-1][k]*\binom{x}{n} 其中(i*x + k) \equiv j mod 9\]
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 100010; const LL mod = 258280327; LL dp[9][maxn]; int hs[10],sum; LL quickPow(LL a,LL b) { LL ret = 1; a %= mod; while(b) { if(b&1) ret = (ret*a)%mod; b >>= 1; a = a*a%mod; } return ret; } LL gcd(LL a,LL b,LL &x,LL &y) { //ax + by = gcd(a,b) if(!b) { x = 1; y = 0; return a; } LL ret = gcd(b,a%b,y,x); y -= x*(a/b); return ret; } LL Inv(LL b,LL mod) { //求b % mod的逆元 LL x,y,d = gcd(b,mod,x,y); return d == 1?(x%mod + mod)%mod:-1; } int main() { int kase,n,A,B,tmp,maxv; scanf("%d",&kase); while(kase--) { scanf("%d%d%d",&n,&A,&B); memset(dp,0,sizeof dp); memset(hs,0,sizeof hs); for(int i = sum = maxv = 0; i < n; ++i) { scanf("%d",&tmp); sum += tmp; maxv = max(maxv,tmp); hs[tmp%9]++; } if(sum%9 != (A + B)%9) { if(maxv <= A && sum%A == 0 || maxv <= B && sum%B == 0) puts("1"); else puts("0"); continue; } A %= 9; dp[0][0] = quickPow(2,hs[0]); for(int i = 1; i < 9; ++i) { LL a = 1,b = 1; for(int j = 0; j <= hs[i]; ++j) { if(j) { a = a*(hs[i] - j + 1)%mod; b = b*j%mod; } LL ret = j?a*Inv(b,mod)%mod:1; for(int k = 0; k < 9; ++k) { int tmp = (i*j + k)%9; dp[i][tmp] += dp[i-1][k]*ret; dp[i][tmp] %= mod; } } } printf("%I64d\n",dp[8][A]); } return 0; }
View Code
相关文章推荐
- HDU 4720 Naive and Silly Muggles
- 1090. Highest Price in Supply Chain (25)
- hdu 1022 Train Problem I
- The 11-th Programming Contest of Hunan University -- Trailing Zeros of Factorials
- 重绘(repaints) 重排(reflows)
- 2015 HUAS Summer Trainning #5~N
- hdu 2523SORT AGAIN
- Elasticsearch 报错:failed to create a selector
- hadoop about "Container does not exist."
- hadoop about "Container does not exist."
- hdu 1022(列车进栈出栈) Train Problem I
- Roundcube Webmail 安装配置图文详情
- LeetCode解题报告--Container With Most Water
- MFC中View类获取CMainFrame的方法
- hdu1021 Fibonacci Again
- kamailio4.2.6 安装和配置教程
- Kamailio负载均衡解决方法汇总
- hdu 4630 No Pain No Game【线段树 离线操作】
- 第十六章、Raid及mdadm命令
- Juniper Contrail SDN Joins Mirantis OpenStack Party