2015多校.Zero Escape (dp减枝 && 滚动数组)

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

2015 Multi-University Training Contest 8

题目本身就这样吧,归纳一下得到结论后就可以dp直接上了。

在比赛时没仔细看(有队友,hhhh),赛后补得时候莫名tle,23333

然后就知道dp是可以剪枝的,剪了跑的话,妥妥的。

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5 const int M = 1e5 + 10 , mod = 258280327 ;
 6 int n , A , B ;
 7 int a[M] ;
 8 int dp[2][10][10] ;
 9 int get (int x) {
10         return x/10 + x%10 ;
11 }
12
13 //void solve () {
14 //        int cur = 0, nxt = 1;
15 //        dp[0][0][0] = 1 ;
16 //        for(int i = 1 ; i <= n ; i ++) {
17 //                 for (int j = 0 ; j < 10 ; j ++) {
18 //                         for (int k = 0 ; k < 10 ; k ++) if (dp[i - 1][j][k] > 0) {
19 //                                 dp[i][ get(j+a[i]) ][k] = (dp[i][ get(j+a[i]) ][k] + dp[i-1][j][k]) % mod ;
20 //                                 dp[i][j][ get(k+a[i]) ] = (dp[i][j][ get(k+a[i]) ] + dp[i-1][j][k]) % mod ;
21 //                         }
22 //                 }
23 //        }
24 //        //cout << dp[n][A][B] << " " << dp[n][A][0] << " " << dp[n][0][B] << endl ;
25 //        printf ("%d\n" , ((dp[n][A][B] + dp[n][A][0]) % mod + dp[n][0][B]) % mod) ;
26 //}
27
28 void add (int &x , int y) {
29         x += y ;
30         if (x > mod) x -= mod ;
31 }
32
33 void solve () {
34         int cur = 0 , nxt = 1 ;
35         memset (dp[cur] , 0 , sizeof(dp[cur])) ;
36         dp[cur][0][0] = 1 ;
37         for (int i = 1 ; i <= n ; i ++) {
38                 memset (dp[nxt] , 0 , sizeof(dp[nxt])) ;
39                 for (int j = 0 ; j < 10 ; j ++) {
40                         for (int k = 0 ; k < 10 ; k ++) {
41                                 if (dp[cur][j][k] == 0) continue ;
42                                 add (dp[nxt][ get(j+a[i]) ][k] , dp[cur][j][k])  ;
43                                 add (dp[nxt][j][ get(k+a[i]) ] , dp[cur][j][k])  ;
44                         }
45                 }
46                 swap (cur , nxt) ;
47         }
48         printf ("%d\n" , ((dp[cur][A][B] + dp[cur][A][0]) % mod + dp[cur][0][B]) % mod) ;
49 }
50
51 int main () {
52         int T ;
53         scanf ("%d" , &T ) ;
54         while (T --) {
55                 scanf ("%d%d%d" , &n , &A , &B) ;
56                 for (int i = 1 ; i <= n ; i ++) {
57                         scanf ("%d" , &a[i]) ;
58                         //memset (dp[i] , 0 , sizeof(dp[i])) ;
59                 }
60                 a[0] = 0 ;
61                 solve () ;
62         }
63         return 0 ;
64 }

时间: 2024-09-29 08:56:19

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

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

C. Arcade time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Abdullah and Haritha were building a 3D printed arcade machine. Abdullah had worked on the hardware, while Haritha had been working

【SDOI】【DP】【滚动数组】【bzoj1925】地精部落

1925: [Sdoi2010]地精部落 Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 814  Solved: 494 [Submit][Status][Discuss] Description 传说很久以前,大地上居住着一种神秘的生物:地精. 地精喜欢住在连绵不绝的山脉中.具体地说,一座长度为 N 的山脉 H可分 为从左到右的 N 段,每段有一个独一无二的高度 Hi,其中Hi是1到N 之间的正 整数. 如果一段山脉比所有与它相邻的山脉都高,则

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

bitset的经典优化,即把可行性01数组的转移代价降低 bitset的适用情况,当内层状态只和外层状态的上一个状态相关,并且内层状态的相关距离是一个固定的数,可用bitset,换言之,能用滚动数组是能用bitset优化的前提 /* dp[i,j][0|1|2]表示p串的第i位,s串的第j位相匹配,pi和pi-1换,pi不换,pi和pi+1换的状态下是否能匹配 dp[i,j][0] = dp[i-1,j-1][2] & p[i-1]==s[j] dp[i,j][1] = (dp[i-1,j-1]

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

转移方程很显然. 因为是多段图模型,所以可以滚动数组优化一维空间. #include<cstdio> #include<cstring> using namespace std; int m,K,n,p; bool zaw[1010][30010]; double f[2][30010]; int main(){ int x,y; bool flag=1; scanf("%d%d%d%d",&m,&K,&n,&p); for(in

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

Zero Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 56    Accepted Submission(s): 18 Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikos

hdu5289||2015多校联合第一场1002贪心+RMQ

http://acm.hdu.edu.cn/showproblem.php?pid=5289 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n in this company, and every staff has a ability. Now, Tom is going to assign a special task to

hdu5351(2015多校5)--MZL&#39;s Border(打表,,找规律)

题目链接:点击打开链接 题目大意:给出b1 = 'b' , b2 = 'a' , bi = b(i-1)b(i-2),将i-1和i-2链接起来,记录一个串的s[1-i] 和s[n-i+1-n]相同的话 Border,当i为最长是为LBorder,现在给让求在bn这个串上的前m个字符组成的子串的LBorder 通过计算可以发现,b字符串的前缀都是相同的,所以只要求出m的LBorder就行,和n是无关的,打表找出规律,找出对应不同的m,LBorder的值,因为存在大数,用java写 dp[i]第i层

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分相同,第一部分与第二部分对称. 现在给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法,求出以第i个点为中心的回文串长度,记录到数组p中 要满足题目所要求的内容,需要使得两个相邻的回文串,共享中间的一部分,也就是说,左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也是一样. 因为我们已经记录下来以

HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&amp;#39;s problem(manacher+二分/枚举)

pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序列,求出该序列中N序列的最大长度. 思路: 来自官方题解:修正了一些题解错别字(误 先用求回文串的Manacher算法.求出以第i个点为中心的回文串长度.记录到数组p中 要满足题目所要求的内容.须要使得两个相邻的回文串,共享中间的一部分,也就是说.左边的回文串长度的一半,要大于等于共享部分的长度,右边回文串也