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