HDU5389:Zero Escape(dp & 类背包)
来源:互联网 发布:国外的移动网络制式 编辑:程序博客网 时间:2024/05/20 18:45
Zero Escape
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1578 Accepted Submission(s): 801
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 of65536 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 numberedX(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, numberedA and B . Maybe A=B , but they are two different door.
And there isn 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 door9 . 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 .
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
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
For example, players
There is two doors, numbered
And there is
For example:
players are
There is only one way to distribute the players: all players get into the door
Given the identifier of every player, please calculate how many kinds of methods are there,
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 integersn , A and B .
Next line containsn integers idi , describing the identifier of every player.
T≤100 , n≤105 , ∑n≤106 , 1≤A,B,idi≤9
For each test case, the first line contains three integers
Next line contains
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
43 9 11 2 63 9 12 3 35 2 31 1 1 1 19 9 91 2 3 4 5 6 7 8 9
Sample Output
101060
Author
SXYZ
Source
2015 Multi-University Training Contest 8
题意:给两扇门A和B,两扇门都有一个数值(范围1~9),将N个人分成两组,两组的数根(定义为将各位的数字不断求和直至剩下一个数)分别与门上的数值一致,表示一个分组方案,求总的分组方案数,当全部人恰好能分去A(或B),而B(或A)没有人时,也算一种方案。思路:显然能恰好分成两组到两扇门时,有总人数的数根sum和a+b的数根相等,定义dp[i][j] 表示前i个人选若干人的数根为j的方案数,易得dp[i][j] = dp[i-1][j] + dp[i][j-c[k]],当j-c[k]不为正数时要分类讨论。结果先判断sum和a+b数根相不相等,若不等说明不存在能够分成两组的情况,只需(*)判断能不能全部人去A门或B门,若相等显然dp[n][a](或dp[n][b])即为结果,这时候为保证绝对是分成两组的情况,再判断a门(上面取dp[n][b]时判断b门)数组是否等于sum,是就减去1,再特判(*)处的情况。
# include <stdio.h># include <string.h># define MOD 258280327# define MAXN 100000int arr[MAXN+3], dp[MAXN][11];int fun(int a, int b){ int temp = (a+b)%9; return temp==0?9:temp;}int main(){ int T, n, a, b, i, j, ans, sum, result; scanf("%d",&T); while(T--) { memset(dp,0,sizeof(dp)); result = sum = 0; scanf("%d%d%d",&n,&a,&b); for(i=1; i<=n; ++i) { scanf("%d",&arr[i]); sum = fun(sum, arr[i]); } dp[1][arr[1]] = 1; for(i=2; i<=n; ++i) { for(j=1; j<=9; ++j) { ans = j-arr[i]; if(ans < 0) dp[i][j] = (dp[i-1][j] + dp[i-1][ans+9]) % MOD; else if(ans == 0) dp[i][j] = (dp[i-1][j] + dp[i-1][9] + 1) % MOD; else dp[i][j] = (dp[i-1][j] + dp[i-1][ans]) % MOD; } } if(sum == fun(a, b)) { result = dp[n][a]; if(a==sum) --result; } if(a == sum) ++result; if(b == sum) ++result; printf("%d\n",result); } return 0;}
0 0
- HDU5389:Zero Escape(dp & 类背包)
- hdu5389 Zero Escape(DP)
- hdu5389 Zero Escape(模拟+找规律+DP)
- hdu5389(2015多校8)--Zero Escape(dp)
- HDU5389.Zero Escape
- hdu5389 Zero Escape
- hdu5389 Zero Escape
- hdu5389 Zero Escape(动态规划)
- hdu 5389 Zero Escape(dp类似背包)
- hdu5389 Zero Escape DP+滚动数组 多校联合第八场
- hdu 5389 Zero Escape (DP+类似01背包)
- hdu 5389 Zero Escape(dp)
- hdu 5389 Zero Escape(dp)
- 计数DP(Zero Escape,HDU 5389)
- HDU 5389 Zero Escape (类0/1背包)
- hdu(5389)——Zero Escape(01背包变形)
- hdu 5389 Zero Escape(dp)
- HDOJ 5389 Zero Escape DP
- Java的环境变量
- 连续第一百零一十二天
- 哈希查找算法(php)
- 支付宝使用的开源组件总结
- Java NIO Selector详解
- HDU5389:Zero Escape(dp & 类背包)
- Android setTextSize
- RxJava笔记
- PART II 信息层 Chapter 3 数据表示法
- 中国管理文化与需求分析中的陷阱之领导和员工话语权问题
- 转载张龙老师一篇关于IntelliJ IDEA的介绍
- express框架
- 用户管理材料
- PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0