Zero Escape

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 407    Accepted Submission(s): 190

Problem Description

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

Output
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.
 
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

解题:动态规划

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 = ;
const LL mod = ;
LL dp[][maxn];
int hs[],sum;
LL quickPow(LL a,LL b) {
LL ret = ;
a %= mod;
while(b) {
if(b&) ret = (ret*a)%mod;
b >>= ;
a = a*a%mod;
}
return ret;
}
LL gcd(LL a,LL b,LL &x,LL &y) { //ax + by = gcd(a,b)
if(!b) {
x = ;
y = ;
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 == ?(x%mod + mod)%mod:-;
}
int main() {
int kase,n,A,B,tmp,maxv;
scanf("%d",&kase);
while(kase--) {
scanf("%d%d%d",&n,&A,&B);
memset(dp,,sizeof dp);
memset(hs,,sizeof hs);
for(int i = sum = maxv = ; i < n; ++i) {
scanf("%d",&tmp);
sum += tmp;
maxv = max(maxv,tmp);
hs[tmp%]++;
}
if(sum% != (A + B)%) {
if(maxv <= A && sum%A == || maxv <= B && sum%B == )
puts("");
else puts("");
continue;
}
A %= ;
dp[][] = quickPow(,hs[]);
for(int i = ; i < ; ++i) {
LL a = ,b = ;
for(int j = ; j <= hs[i]; ++j) {
if(j) {
a = a*(hs[i] - j + )%mod;
b = b*j%mod;
}
LL ret = j?a*Inv(b,mod)%mod:;
for(int k = ; k < ; ++k) {
int tmp = (i*j + k)%;
dp[i][tmp] += dp[i-][k]*ret;
dp[i][tmp] %= mod;
}
}
}
printf("%I64d\n",dp[][A]);
}
return ;
}

最新文章

  1. Auty 2017——WebMonitor接口检测平台
  2. iOS开发 Masonry的简单使用
  3. python高效解析日志入库
  4. Windows和Linux上用C与Lua交互
  5. OCR文字识别软件许可文件被误删了怎么办
  6. *J2EE中乱码处理
  7. Cocos2d-x中常用粒子编辑器ParticleDesigner测试例子
  8. 高效的TCP消息发送组件
  9. 【Android】数据的应用-使用sharedpreferences存储数据
  10. Linux常用命令手册
  11. bzoj 3048[Usaco2013 Jan]Cow Lineup 思想,乱搞 stl
  12. BZOJ_3011_[Usaco2012 Dec]Running Away From the Barn _可并堆
  13. 用shell统计表格数据
  14. ORA-00257:archiver error问题处理方法
  15. java使用DateUtils对日期进行运算
  16. Linux常用基本命令(file,chown)
  17. Java中的RTTI
  18. 编译环境搭建:Makefile
  19. MySQL中的共享锁
  20. nginx 安装 lua-nginx-module

热门文章

  1. CodeForcesGym 100548G The Problem to Slow Down You
  2. iOS 使用脚本自动化复制target
  3. 兔子-RadioButton和RadioGroup的关系
  4. 【BZOJ 2821】作诗
  5. 剑指offer——03从尾至头打印列表(Python3)
  6. Java入门第一季
  7. Python 函数(二)
  8. 基于Redis实现分布式应用限流--转
  9. vue中通过js控制页面样式方法
  10. PHP的分页