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. pack、unpack自制二进制“数据库”

    引言 pack.unpack函数,如果没有接触过socket,这个可能会比较陌生,这两个函数在socket交互的作用是组包,将数据装进一个二进制字符串,和对二进制字符串中的数据进行解包,这个里面有好多 ...

  2. primefaces p:tableData 显示 List<List>

    @javax.faces.bean.ViewScoped public class Controlador { private List<List> estadistico; @PostC ...

  3. 关于vs生成app错误提示,提醒Execution failed for task ':transformClassesWithDexForDebug'.

    昨天将vs和android SDK更新之后生成app之后发现app生成出错,报错如下: FAILURE: Build failed with an exception. * What went wro ...

  4. app的描述

    app的描述=需求文档+接口文档+程序架构.   程序架构:类结构图: 需求文档:业务逻辑-->时序图.

  5. angularjs中$watch监听model(对象属性、对象)变化

    昨天看了一下教学视频,学到了有关$watch的用法,想到最近做的一个页面中有个select下拉选项(select中的值变化了,则后面input中的值也跟着相应的变化),不知是否可以使用$watch来代 ...

  6. wifi-mac

    //18:a6:f7:12:0b:8b //18:a6:f7:1e:a9:57 //18:a6:f7:1f:8e:69 //18:a6:f7:12:0b:9c //18:a6:f7:1f:cd:d4 ...

  7. CodeForces 716B Complete the Word

    题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...

  8. php 多条数据更新

    mysql更新语句很简单,更新一条数据的某个字段,一般这样写: 1 UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_va ...

  9. Struts2 中Parameters是如何获取值的

    刚刚学习struts2的知识,在练习struts2的默认语言OGNL过程中,对于<p>parameters:<s:property value="#parameters.u ...

  10. java enum类

    1.可以在enum中添加变量和方法 先来看一段代码示例: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...