博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5389 Zero Escape
阅读量:6672 次
发布时间:2019-06-25

本文共 4125 字,大约阅读时间需要 13 分钟。

Zero Escape

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 1460    Accepted Submission(s): 716

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(1X9), 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=9B=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 nA and B.
Next line contains n integers idi, describing the identifier of every player.
T100n105n1061A,B,idi9
 

 

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
 

 

Author
SXYZ
 

 

Source
 
 
 
16464431 2016-03-07 10:54:36 Accepted 483MS 6260K G++
 
题解:
先转一发题解:
解题:

 

    比赛的时候是水过的,不得不吐槽下多校的数据真水,听说样例都没过也能A。之前发了错误的题解,实在是抱歉,现在改正了。之前大致思路是对的:

    dp[i][j]=dp[i-1][j]+dp[i-1][tmp](tmp为j-arr[i],若小于等于0,需加9调整)

    dp[i][j]含义为取前i个数字中的若干个,按给定规则,算出来的和为j的方案数

    之前有两个细节没考虑到,

    一是、当前位和我dp[i][j]中的j值相同,那么对应三种情况。

    1.当前位不取,直接取前面dp[i-1][j]的值

    2.当前位取,前面取的是dp[i-1][9]的值(因为加9,不变)

    3.当前位取,前面都不取,此种情况特殊,直接加一即可。

    其实2、3两种情况是一个数分别对应dp[i-1][0]和dp[i-1][9]的特殊情况。

    二是、当a+b的和和sum相同时,最后输出结果的时候,按理说只要输出dp[n][a]就可以了,但是这样会遗漏a中都不取,全都放在b中,而b又刚好和sum相同的情况。

    现在是没有错误了,请放心看微笑

 

注意点:

开始想到dp了,不过傻傻的用了3维dp,结果超时了,没注意到一部分人进了A门,那么剩下的人肯定要进B门,所以第三维可以省掉。

 
转移方程:
for(o = 1;o <= n;o++){        for(i = 0;i <= 9;i++){            t = (9+i-x[o]) % 9;            dp[o][i] = (dp[o-1][t] + dp[o-1][i]) %mod;        }    }

 

 
 
代码:
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 12 #define ll long long13 #define N 10000514 #define mod 25828032715 16 using namespace std;17 18 int T;19 int n,a,b;20 int x[N];21 int dp[N][11];22 int ans;23 int s;24 25 int root(int x) { return (x-1)%9+1;}26 27 void solve()28 {29 int i,o;30 int t;31 dp[0][0] = 1;32 for(o = 1;o <= n;o++){33 for(i = 0;i <= 9;i++){34 t = (9+i-x[o]) % 9;35 dp[o][i] = (dp[o-1][t] + dp[o-1][i]) %mod;36 }37 }38 }39 40 int main()41 {42 //freopen("in.txt","r",stdin);43 scanf("%d",&T);44 for(int ccnt=1;ccnt<=T;ccnt++){45 //while(scanf("%d%s%s",&n,a,b)!=EOF){ 46 scanf("%d%d%d",&n,&a,&b);47 memset(dp,0,sizeof(dp));48 int i;49 s = 0;50 for(i = 1;i <= n;i++){51 scanf("%d",&x[i]);52 s = root(s+x[i]);53 }54 solve();55 ans = 0;56 if(root(a+b)==s) ans+=dp[n][a];57 else if(a==s) ++ans;58 if(b==s) ++ans;59 printf("%d\n",ans%mod);60 }61 return 0;62 }

 

转载于:https://www.cnblogs.com/njczy2010/p/5249785.html

你可能感兴趣的文章
G.Longest Palindrome Substring
查看>>
gdb个人使用记录
查看>>
c++ set和pair 的结合使用
查看>>
C#中哈希表(HashTable)的用法详解
查看>>
一起学Android之ListView
查看>>
nginx 配置geoip 屏蔽地区城市,实现判断国家IP跳转
查看>>
换行显示print_r($arr);打印结果显示:Array( [0] => 百度 [1] => 阿里)
查看>>
第二个Sprint冲刺第 七天(燃尽图)
查看>>
ruby 升级1.8.7到1.9.3
查看>>
linux网络配置命令(一)——ifconfig
查看>>
xcode10设置自定义代码快 - Xcode10新功能新内容
查看>>
【BZOJ】4559: [JLoi2016]成绩比较 计数DP+排列组合+拉格朗日插值
查看>>
【vijos】P1448 校门外的树
查看>>
【BZOJ】2440: [中山市选2011]完全平方数
查看>>
二十四种设计模式:原型模式(Prototype Pattern)
查看>>
小程序右侧边栏
查看>>
小白的Python 学习笔记(八)推导式详解
查看>>
解决sublimeText3无法安装插件有关问题 - There are no packages available for installation
查看>>
一篇文章帮你彻底搞清楚“I/O多路复用”和“异步I/O”的前世今生
查看>>
Xamarin.android 重写axml控件
查看>>