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 ;
}

2015多校.Zero Escape (dp减枝 && 滚动数组)的更多相关文章

  1. 2017 Hackatari Codeathon C. Arcade(DP)(滚动数组)

    C. Arcade time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  2. hdu5745 La Vie en rose 巧妙地dp+bitset优化+滚动数组减少内存

    /** 题目:hdu5745 La Vie en rose 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5745 题意:题目给出的变换规则其实就是交换相邻 ...

  3. 字符串匹配dp+bitset,滚动数组优化——hdu5745(经典)

    bitset的经典优化,即把可行性01数组的转移代价降低 bitset的适用情况,当内层状态只和外层状态的上一个状态相关,并且内层状态的相关距离是一个固定的数,可用bitset,换言之,能用滚动数组是 ...

  4. 【AC自动机】【状压dp】【滚动数组】hdu6086 Rikka with String

    给你m个01串,问你有多少个长度为2L的01串,满足前半段倒置取反后等于后半段,并且包含所有的m个01串. 考虑单词完全在中线前面或者后面的情况,直接将单词及其倒置取反插入AC自动机,AC自动机每个结 ...

  5. 【概率dp】【滚动数组】CDOJ1652 都市大飙车

    转移方程很显然. 因为是多段图模型,所以可以滚动数组优化一维空间. #include<cstdio> #include<cstring> using namespace std ...

  6. Palindrome_滚动数组&&DP

    Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...

  7. poj1159 dp(滚动数组优化)

    H - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:65536KB     ...

  8. DP一直是自己的弱势 开始练滚动数组——HDOJ4502

    http://acm.hdu.edu.cn/showproblem.php?pid=4502//题目链接 思路 : dp[i]表示 到第i天能获得的最大工资  依次更新 #include<cst ...

  9. hdu5389 Zero Escape DP+滚动数组 多校联合第八场

    Zero Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

随机推荐

  1. PHP预定义接口

    目录 引言 IteratorAggregate(聚合式aggregate迭代器Iterator) Countable ArrayAccess Iterator 总结 引言 在PHP中有好几个预定义的接 ...

  2. Aspx生命周期

    今天去面试,碰到面试官问这个问题.aspx页面生命周期是什么?顿时懵逼 还跟我解释:就是页面怎么解析的aspx页面.果断没看过这方面知识,没答上来.现在记录一下 ASP.NET页面生命周期 ASP.N ...

  3. HDU 4388 To the moon

    传送门 To the moon Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. android开发中遇到的各种问题收集--不定期更新

    以下问题都是自己在开发中亲身碰到的 ,在这里留个备份,方便下次查阅. 1.java.lang.IllegalStateException ,Cannot execute task: the task ...

  5. Mysql 列转行统计查询 、行转列统计查询

      -- ---------------------------- -- Table structure for `TabName` -- ---------------------------- D ...

  6. jboss性能优化

    jboss     linux jboss 部署时优化设置: 在/conf/web.xml中通过参数指定: <session-config>          <session-ti ...

  7. (转)雅虎工程师提供的css初始化示例代码

    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,b ...

  8. JavaScript函数之美~

    JavaScript函数之美~ 这篇文章,我将就以下几个方面来认识JavaScript中的函数. 函数为什么是对象,如何定义函数? 如何理解函数可以作为值被传递 函数的内部对象.方法以及属性 第一部分 ...

  9. ASP------如何使界面布局具有一致外观

    使用布局页或布局块的方法 转载: http://www.runoob.com/aspnet/webpages-layout.html

  10. Visual Studio的调试技巧

    Visual Studio的调试技巧 [原文地址] Debugging Tips with Visual Studio 2010 [原文发表日期] 2010/8/19 10:48 AM 这是我写的关于 ...