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 ...
随机推荐
- RadioGroup单选按钮排版
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- 再谈Cookies欺骗
在上一篇关于cookies欺骗的随笔中,提到的解决方案是把密码MD5加密之后存入cookies中,确实这种方法实现了效果,不过把密码留在客户端等待着去被破解不是一个合适的方法,在此也感谢 @老牛吃肉 ...
- 微软分布式缓存 appfabric
appfabric为微软自家产的分布式缓存解决方案,随dotnet4.0一起发布.目前版本为1.1
- jQuery.YesShow - 图片轮播插件(带图片放大功能)
jQuery.YesShow - 图片轮播插件(带图片放大功能) 使用简单,原文件只要这样就可以了:<div id="yes"> <ul> ...
- ECSTORE AJAX提交的实现
今天向大家介绍在ecstore中怎样使用ajax提交数据 1 <script> //JAVASCRIPT代码 $$(".BB").ADDEVENT('CHANGE',F ...
- PHPCMS v9构建模块 - 实例之企业服务模块
下面开始第一个实例,企业服务模块,这是个比较简单的模块,做一个抛砖的作用. 模块功能分析:企业服务,企业填写招聘申请表,管理审核之后,展示作为招聘通知的功能. ■1.文件分布 modules文 ...
- PHP高效的敏感词过滤方法
<?php // 测试文件demo.php $badword = array( '张三','张三丰','张三丰田' ); // array_combine() 函数通过合并两个数组来创建一个新数 ...
- sersync做实时同步(第一步)
两台主机,一台主服务器(192.168.0.109).一台目标服务器(192.168.0.212) 1.配置目标服务器(192.168.0.212);就是配置rsync服务器.在配置文件/etc/rs ...
- mysql 查询每个分组前N条记录
mysql 查询每个分组前N条记录 假设存在表movie, 有字段 id, part(地区), mcount(观看次数) 现查询每个地区观看次数最多的3部movie, 则表 ###id虽未存在gro ...
- Android利用百度地图定位
百度地图照着百度的教程做的总是出现报错 请帮我看看错误在那 2013-12-13 15:16168海军 | 分类:百度地图 | 浏览1252次 java.lang.RuntimeException: ...