hdu 5389 Zero Escape(记忆化搜索)
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<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define N 100006
#define M 16
#define MOD 258280327
int n,A,B;
int dp[N][M];
int a[N];
int sum;
int dfs(int cur,int suma,int now)
{
if(dp[cur][suma]!=-) return dp[cur][suma];
if(cur>n)
{
if(now==)
{
return (sum-now)%==B;
}
if(now==sum)
{
return suma == A;
}
return suma==A && (sum-now)%==B;
} dp[cur][suma]=dfs(cur+,(suma+a[cur])%,now+a[cur])+dfs(cur+,suma,now);
return dp[cur][suma]%=MOD;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&A,&B);
if(A==)
A=;
if(B==)
B=;
sum=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
} memset(dp,-,sizeof(dp));
printf("%d\n",dfs(,,));
}
return ;
}
hdu 5389 Zero Escape(记忆化搜索)的更多相关文章
- [HDU 1428]--漫步校园(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1428 漫步校园 Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 4597 Play Game(记忆化搜索)
题目链接:hdu 4597 Play Game 题目大意:给出两堆牌,仅仅能从最上和最下取,然后两个人轮流取,都依照自己最优的策略.问说第一个人对多的分值. 解题思路:记忆化搜索,状态出来就很水,dp ...
- hdu 4856 Tunnels (记忆化搜索)
Tunnels Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- HDU 4597 Play Game(记忆化搜索,深搜)
题目 //传说中的记忆化搜索,好吧,就是用深搜//多做题吧,,这个解法是搜来的,蛮好理解的 //题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,//问说第一个人对多的 ...
- HDU 5001 概率DP || 记忆化搜索
2014 ACM/ICPC Asia Regional Anshan Online 给N个点,M条边组成的图,每一步能够从一个点走到相邻任一点,概率同样,问D步后没走到过每一个点的概率 概率DP 測 ...
- HDU 4597 Play Game (记忆化搜索博弈DP)
题意 给出2*n个数,分两列放置,每列n个,现在alice和bob两个人依次从任意一列的对头或队尾哪一个数,alice先拿,且两个人都想拿最多,问alice最后能拿到数字总和的最大值是多少. 思路 4 ...
- HDU 3779 Railroad(记忆化搜索)
Railroad Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Subm ...
- hdu 5535 Cake 构造+记忆化搜索
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5355 题意:给定n与m,其中1<= n <= 1e5,2 <= m <= 10;问 ...
- HDU 1176 免费馅饼(记忆化搜索)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
随机推荐
- systemd添加自定义系统服务设置自定义开机启动
1.服务权限 systemd有系统和用户区分:系统(/user/lib/systemd/system/).用户(/etc/lib/systemd/user/).一般系统管理员手工创建的单元文件建议存放 ...
- ERROR<53761> - Plugins - conn=-1 op=-1 msgId=-1 - Connection Bind through PTA failed (91). Retrying...
LDAP6.3在DSCC控制台启动实例完成,但是操作状态显示“意外错误”,查看日志如下: 04/May/2016:21:10:39 +0800] - Sun-Java(tm)-System-Direc ...
- web页面打印
在使用的两种方式打印: 第一种:js如下 function doPrint() { allhtml = window.document.body.innerHTML; starstr = " ...
- 【译】addEventListener 第二个参数
这是原文链接:Our Backwards DOM Event Libraries 浏览器APIs 先简单回顾一下各个浏览器提供了哪些绑定事件的接口. IE浏览器提供了element.attachEve ...
- CactiEZ 中文版V10.1安装使用以及139邮箱短信报警设置
说明:CactiEZ中文版V10.1是基于CentOS 6.0系统,整合Cacti等相关软件,重新编译而成的一个操作系统! 说明:CactiEZ中文版V10.1是基于CentOS 6.0系统,整合 ...
- angularjs自定义日期过滤器,如:周日(前天 21:24)
今天给大家分享一个,我在项目中自定义的一个日期过滤器.具体过滤出来的效果可参看下图: 用法: {{ time | timeFilter }} filter: App.filter('timeFilte ...
- cos实现文件上传--推荐
1.导包 2.核心类:MultipartRequest MultipartRequest是request的包装类 参数1:request 参数2:保存路径 参数3:上传文件大小,默认为1M 参数4:编 ...
- linux vi 使用脑图
- JavaScript获取Select下拉框Option的Value和Text值的方法
Js获取select下拉列表框各个Option的Value值相对比较容易,不过获取Text值却有点麻烦,对于一个初学JavaScript的 新手来说,可能一时还无从下手,那么就请看下本文的方法,以一个 ...
- oracle创建主键序列和在ibatis中应用
oracle创建主键序列 oracle主键序列的查询和ibitas中应用