2015 Multi-University Training Contest 8 hdu 5389 Zero Escape
Zero Escape
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 407 Accepted Submission(s): 190
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
解题:动态规划
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 ;
}
2015 Multi-University Training Contest 8 hdu 5389 Zero Escape的更多相关文章
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 6 hdu 5362 Just A String
Just A String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence
Easy Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- CF 149D Coloring Brackets(区间DP,好题,给配对的括号上色,求上色方案数,限制条件多,dp四维)
1.http://codeforces.com/problemset/problem/149/D 2.题目大意 给一个给定括号序列,给该括号上色,上色有三个要求 1.只有三种上色方案,不上色,上红色, ...
- BA-siemens-点位类型表
X(超级点) 输入 0-10v 4-20ma(不可用) Ni 1000 Pt 1000 10k & 100k 热敏电阻 数字输入 脉冲计数输入 输出 0-10v 4-20ma(不可用) 数字 ...
- zoj 3034 - The Bridges of Kolsberg
题目:在河两端有两排server,如今要把河两边同样的品牌型号的机器连起来.每一个电脑有个值, 每一个机器仅仅能与还有一台机器链接.而且不同的链接不交叉,如今要求链接的电脑总之最大. 分析:dp,最大 ...
- redis代码解析-事务
redis 的事务相关的几个命令分别为 watch multi exec. watch 可以监控一个变量在事务开始执行之前是否有被修改.使用方式为: WATCH key [key ...] 在redi ...
- Milk(杭电1070)
Milk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- flume採集数据导入elasticsearch 配置
Flume启动通常会报两种错,一种是log4j没有配置,第二种就是缺少各种jar包.SO: [root@laiym ~]# cp /usr/local/elasticsearch/lib/*/usr/ ...
- sqlite学习笔记6:更新表数据-update
一 条件推断 在SQL中条件推断使用where,相当于其它变成语言中的if,基本使用方法如: SELECT column1, column2, columnN FROM table_name WHER ...
- OC中的类扩展
类扩展 是在原有类的基础扩展一个新的属性和对象方法 但是方法的实现还是要写在原有的声明中,不然是不会被访问到的 类扩展可以扩展在新的头文件中,然后在主函数中导入. 利用类扩展可以变相的实现属性的私有化 ...
- php开启CURL支持
window下安装php_curl支持 1. 找到php.ini 修改extension=php_curl.dll 把前面的分号去掉2. 把 php_curl.dll libeay32.dll ssl ...
- Linux目录结构(一)
linux文件系统的最顶端是/,称为linux的root,所有的目录.文件.设备都在/之下. 文件类型 linux有四种基本文件系统类型:普通文件.目录文件.连续文件和特殊文件.可以用file命令来识 ...