hdu5389 Zero Escape(模拟+找规律+DP)
来源:互联网 发布:小说软件 编辑:程序博客网 时间:2024/05/09 21:24
Link:http://acm.hdu.edu.cn/showproblem.php?pid=5389
Zero Escape
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 553 Accepted Submission(s): 272
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
Source
2015 Multi-University Training Contest 8
编程思想:按题意模拟求数根。然后DP。
详细分析过程参考自: http://blog.csdn.net/david_jett/article/details/47617099
状态转移方程为dp[i][j]=(dp[i-1][pre]+dp[i-1][j])%mod;其中pre为j-a[i],i是当前下标,j从1到9,若算出的pre小于等于0还需加上9。dp[i][j]的含义是到第i位为止,前i个数中的若干个加起来和为j的方案数,转移方程中的两项分别对应,当前i位取或不取。因为每个数字是由确定的两个数字组合加起来得到的,比如2,若其中一个为1,那么另外一个也一定为1。且存在这样的性质,若干个数,按给定的规则先加,或者分开加,再组合在一起,得到的结果是一样的。故可以先预先把所有的数加起来,若其和与A+B得到的结果相同,那么直接取dp[n][A]+dp[n][B]的值即可,若不同,那么只可以放在任意门中,分别检查一下即可。
AC code:
#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>#define LL long long#define MAXN 1000010 using namespace std;const int mod=258280327;LL dp[100010][10];int a[MAXN];LL sum,sum2,ans;int modify(LL x){int res=0;while(x){res+=x%10;x/=10;}while(res>=10){int temp=res;res=0;while(temp){res+=temp%10;temp/=10;}}return res;}int main(){int n,A,B,m,i,j,pre,t,cas;scanf("%d",&t);cas=0;while(t--){scanf("%d%d%d",&n,&A,&B);sum=0;ans=0;for(i=1;i<=n;i++){scanf("%d",&a[i]);sum+=a[i];}sum=modify(sum);sum2=modify(A+B);memset(dp,0,sizeof(dp));dp[1][a[1]]=1;for(i=2;i<=n;i++){for(j=1;j<=9;j++){pre=j-a[i];if(pre<=0)pre+=9;dp[i][j]=(dp[i-1][pre]+dp[i-1][j])%mod;}}if(sum==sum2){ans=(dp[n][A]+dp[n][B])%mod;printf("%I64d\n",ans);}else{if(sum==A)ans++;if(sum==B)ans++;printf("%I64d\n",ans);}}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(动态规划)
- hdu5389 Zero Escape DP+滚动数组 多校联合第八场
- hdu 5389 Zero Escape(dp)
- hdu 5389 Zero Escape(dp)
- 计数DP(Zero Escape,HDU 5389)
- cf(找规律,模拟)
- HDU2147(模拟找规律)
- FZU1062(找规律+模拟)
- hdu 5389 Zero Escape DP+数学规律 给出证明 2015 Multi-University Training Contest 8
- hdu 5389 Zero Escape(dp)
- HDOJ 5389 Zero Escape DP
- win10 genymotion 无法启动的问题解决
- win2008,IP安全策略下配置一个IP段
- HDU 1305 Immediate Decodability(与1671类似)
- Spring与jdbc连接实现增删改查(二)
- android 判断是否支持闪光灯
- hdu5389 Zero Escape(模拟+找规律+DP)
- Android 判断 网络连接 Internet访问 工具类
- java中两个整数相除得到小数点并保留两位小数的方法
- 快速排序示例
- hdu 5385 The path 2015多校联合训练赛#8 bfs
- hdu 2108 Shape of HDU
- Num 35 : HDOJ : 1241 Oil Deposits [ 深度优先搜索算法 ] [ 非回溯 ][ 图论 ]
- 门控时钟
- jsp中的fn标签的使用