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
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.
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
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
0
10
60
#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减枝 && 滚动数组)的更多相关文章
- 2017 Hackatari Codeathon C. Arcade(DP)(滚动数组)
C. Arcade time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- hdu5745 La Vie en rose 巧妙地dp+bitset优化+滚动数组减少内存
/** 题目:hdu5745 La Vie en rose 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5745 题意:题目给出的变换规则其实就是交换相邻 ...
- 字符串匹配dp+bitset,滚动数组优化——hdu5745(经典)
bitset的经典优化,即把可行性01数组的转移代价降低 bitset的适用情况,当内层状态只和外层状态的上一个状态相关,并且内层状态的相关距离是一个固定的数,可用bitset,换言之,能用滚动数组是 ...
- 【AC自动机】【状压dp】【滚动数组】hdu6086 Rikka with String
给你m个01串,问你有多少个长度为2L的01串,满足前半段倒置取反后等于后半段,并且包含所有的m个01串. 考虑单词完全在中线前面或者后面的情况,直接将单词及其倒置取反插入AC自动机,AC自动机每个结 ...
- 【概率dp】【滚动数组】CDOJ1652 都市大飙车
转移方程很显然. 因为是多段图模型,所以可以滚动数组优化一维空间. #include<cstdio> #include<cstring> using namespace std ...
- Palindrome_滚动数组&&DP
Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...
- poj1159 dp(滚动数组优化)
H - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:3000MS Memory Limit:65536KB ...
- DP一直是自己的弱势 开始练滚动数组——HDOJ4502
http://acm.hdu.edu.cn/showproblem.php?pid=4502//题目链接 思路 : dp[i]表示 到第i天能获得的最大工资 依次更新 #include<cst ...
- hdu5389 Zero Escape DP+滚动数组 多校联合第八场
Zero Escape Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
随机推荐
- C++ 之const Member Functions
Extraction from C++ primer 5th Edition 7.1.2 The purpose of the const that follows the parameter lis ...
- 如何解决Response.Redirect方法传递汉字丢失或乱码问题?
为了确保传递的汉字被正确地接收,可以在传值之前使用Server对象的UrlEncode方法对所传递的汉字进行URL编码.代码如下: String name = Server.UrlEncode(&qu ...
- Spider爬虫清洗数据(re方法)
import re s0 = 'BOY and GIRL' s1 = re.sub(r'BOY|GIRL', 'HUMAN', s0) print s1 # HUMAN and HUMAN 替换方法.
- java-HashMap方法讲解
前言:Java8之后新增挺多新东西,在网上找了些相关资料,关于HashMap在自己被血虐之后痛定思痛决定整理一下相关知识方便自己看.图和有些内容参考的这个文章:http://www.importnew ...
- 演示get、post请求如何算sn,算得sn如何使用
import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.UnsupportedEncoding ...
- 总结jQuery选择器
基本选择器 1. id选择器(指定id元素) 2. class选择器(遍历css类元素) 3. element选择器(遍历html元素) 4. * 选择器(遍历所有元素) 5. 并列选择器$('p,d ...
- JS-window对象集合
知识点表格截图:
- WinForm------TreeListLookUpEdit控件的使用
1.数据库添加表dbo.Graduation 2.从工具栏拖出TreeListLookUpEdit控件,修改部分属性 Display Name:选中后显示在控件的值 Value Member:C#代码 ...
- WinForm------GridControl右键添加动态菜单
转载:http://www.devexpresscn.com/Resources/Documentation-440.html 更加好用的方法: 1.添加一个GridControl控件,PopupMe ...
- nginx访问日志获取访问前10的url
在ELK里面获取top10的url在日志量非常大的情况下是非常消耗内存的,所以写了一个脚本用来快速获取. 配置文件 log.conf [log] log_file = /data/logs/nginx ...