Zero Escape

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

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直接上了。
在比赛时没仔细看(有队友,hhhh),赛后补得时候莫名tle,23333
然后就知道dp是可以剪枝的,剪了跑的话,妥妥的。
 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int M = 1e5 + , mod = ;
int n , A , B ;
int a[M] ;
int dp[][][] ;
int get (int x) {
return x/ + x% ;
} //void solve () {
// int cur = 0, nxt = 1;
// dp[0][0][0] = 1 ;
// for(int i = 1 ; i <= n ; i ++) {
// for (int j = 0 ; j < 10 ; j ++) {
// for (int k = 0 ; k < 10 ; k ++) if (dp[i - 1][j][k] > 0) {
// dp[i][ get(j+a[i]) ][k] = (dp[i][ get(j+a[i]) ][k] + dp[i-1][j][k]) % mod ;
// dp[i][j][ get(k+a[i]) ] = (dp[i][j][ get(k+a[i]) ] + dp[i-1][j][k]) % mod ;
// }
// }
// }
// //cout << dp[n][A][B] << " " << dp[n][A][0] << " " << dp[n][0][B] << endl ;
// printf ("%d\n" , ((dp[n][A][B] + dp[n][A][0]) % mod + dp[n][0][B]) % mod) ;
//} void add (int &x , int y) {
x += y ;
if (x > mod) x -= mod ;
} void solve () {
int cur = , nxt = ;
memset (dp[cur] , , sizeof(dp[cur])) ;
dp[cur][][] = ;
for (int i = ; i <= n ; i ++) {
memset (dp[nxt] , , sizeof(dp[nxt])) ;
for (int j = ; j < ; j ++) {
for (int k = ; k < ; k ++) {
if (dp[cur][j][k] == ) continue ;
add (dp[nxt][ get(j+a[i]) ][k] , dp[cur][j][k]) ;
add (dp[nxt][j][ get(k+a[i]) ] , dp[cur][j][k]) ;
}
}
swap (cur , nxt) ;
}
printf ("%d\n" , ((dp[cur][A][B] + dp[cur][A][]) % mod + dp[cur][][B]) % mod) ;
} int main () {
int T ;
scanf ("%d" , &T ) ;
while (T --) {
scanf ("%d%d%d" , &n , &A , &B) ;
for (int i = ; i <= n ; i ++) {
scanf ("%d" , &a[i]) ;
//memset (dp[i] , 0 , sizeof(dp[i])) ;
}
a[] = ;
solve () ;
}
return ;
}

最新文章

  1. 使用adagio包解决背包问题
  2. 关于as3调用js报“null为空或不是对象”错误
  3. android动态注册监听网络变化异常
  4. java中如何获取昨天的当前日期
  5. Editor Scripting学习笔记之Menu Item
  6. iOS开发——语法篇&amp;swift经典语法总结
  7. 【日语】secret base
  8. 从BufferedImage到InputStream,实现绘图后进行下载(生成二维码图片并下载)
  9. 设置不输入密码ssh登录
  10. Javaweb项目碰到的问题- Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES)
  11. sed修炼系列(四):sed中的疑难杂症
  12. wpf 添加滚动条 ScrollViewer
  13. for语句查看js对象
  14. 洛谷P1494小Z的袜子 [国家集训队] 莫队
  15. tableView cell 设置圆角 响应链
  16. 【3】【MOOC】Python游戏开发入门-北京理工大学【第三部分-游戏开发之机制(事件处理机制)】
  17. 基于canvas的仪表盘效果
  18. Python爬虫(七)
  19. 使用wifi网卡笔记4---工具dhcp及全自动使用wifi
  20. iOS float小数四舍五入

热门文章

  1. MOOCULUS微积分-2: 数列与级数学习笔记 5. Another comparison test
  2. 【Alpha阶段】第八次Scrum例会
  3. 【项目】Http请求在NSMutableURLRequest添加HttpBody的字典params属性
  4. python 培训之Django
  5. mysql php query steps
  6. dotnetbar入门
  7. tail 命令 查看Tomcat目录下日志的最后几行的方法
  8. 图解HTTPS协议加密解密全过程
  9. 远程连接实验室的VPN
  10. 转: CvMat,Mat和IplImage之间的转化和拷贝