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 ...
随机推荐
- 两台Linux机之间传送文件
最近实验室里接管了一台服务器,经常需要用到服务器与自己主机之间进行文件传输,因此,在此介绍一下两台Linux主机之间的一些操作,方便后来者. 1. Linux.Windows主机远程访问Linux服务 ...
- php的一些基本概念梳理
楼主是个刚参加工作的菜鸟,这几天刚开通博客园微博,想通过这个平台与大家共同学习与分享一些技术知识. 但是楼主犹豫的好久,不知道第一篇该写点什么.最后我决定先从php的一些基本概念开始,以便加深对各个概 ...
- mySQL优化 my.ini 配置说明
[mysqld] port = 3306 serverid = 1 socket = /tmp/mysql.sock skip-name-resolve #禁止MySQL对外部连接进行DNS解析,使用 ...
- Android v2.0 基本概念 - 浅谈
目录 Android框架 Linux Kernel 系统运行库 Libraries Android Runtime Application Framework Application Android框 ...
- 【转】Mysql三种备份详解
一.备份的目的 做灾难恢复:对损坏的数据进行恢复和还原需求改变:因需求改变而需要把数据还原到改变以前测试:测试新功能是否可用 二.备份需要考虑的问题 可以容忍丢失多长时间的数据:恢复数据要在多长时间内 ...
- CAGradientLayer实现色差动画
效果图: 代码部分: RPGradientAnimationView.h #import <UIKit/UIKit.h> typedef enum : NSUInteger { RPGra ...
- (三)Angularjs - 小实例
AngularJS处理数据表格 使用 np-repeat 指令 <table> ... <!-- 这里使用ng-repeat指令来重复数据生成表格 --> <tr ng- ...
- web项目环境搭建(1):建立一个maven项目
一.maven简介以及常用概念 1.Maven是一个项目管理和整合的工具.Maven为开发者提供了一套完整的构建生命周期框架.开发团队基本不用花多少时间就能自动完成工程的基础构建配置,因为Maven使 ...
- 武汉科技大学ACM:1010: 零起点学算法89——母牛的故事
Problem Description 有一头母牛,它每年年初生一头小母牛.每头小母牛从第四个年头开始,每年年初也生一头小母牛.请编程实现在第n年的时候,共有多少头母牛? Input 输入数据由多个测 ...
- 使用shiro标签遇到的部分问题的解决思路
最近几天,在shiro进行系统权限控制.在处理JSP页面的时候,遇到几个问题,纠结好几天,终于成功解决这些问题. 1.使用<shiro:principal>的时候,如何得到整个类的信息? ...