hdu5389 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.
the number of test cases.
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
can get into these two doors.
4
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 这题关键是要发现定义的运算,起结果和该数%9的结果是一样的,然后能够开个数组dp[i][j](j属于0~8)表示前i个数能选出的数的和%9后为j的方案数。然后dp[i][j]=dp[i-1][j]以及dp[i][(j+c[i]%9)%9]=(dp[i][(j+c[i]%9)%9]+dp[i-1][j])%258280327。dp[]的过程中相当于把9当做0。注意dp的初始化。不然会出错。#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
int c[100060];
int dp[1000060][10]; int main()
{
int n,m,i,j,T,a,b,sum,t1,t2,t,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&a,&b);
sum=0;
for(i=1;i<=n;i++){
scanf("%d",&c[i]);
sum+=c[i];
}
if(sum%9!=(a%9+b%9)%9 && sum%9!=a%9 && sum%9!=b%9){
printf("0\n");continue;
}
t1=a%9;t2=b%9;t=sum%9;
dp[0][0]=1;
for(i=1;i<=n;i++){
for(j=0;j<=8;j++){
dp[i][j]=dp[i-1][j];
}
for(j=0;j<=8;j++){
dp[i][(j+c[i]%9)%9]=(dp[i][(j+c[i]%9)%9]+dp[i-1][j])%258280327;
}
}
if((t1+t2)%9!=t){
if(t1==t && t2==t){
printf("2\n");continue;
}
printf("1\n");continue;
}
printf("%d\n",dp[n][a%9]);
}
return 0;
}
hdu5389 Zero Escape的更多相关文章
- hdu5389 Zero Escape DP+滚动数组 多校联合第八场
		Zero Escape Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ... 
- [hdu5389 Zero Escape]数根的性质,DP
		题意:把n个数(1-9)放到A集合和B集合里面去,使得A集合里面的数的数根为a,B集合里面的数的数根为b,也可以只放在A或B任一个集合里面.求方法总数.比如A={2,4,5},则A的数根为[2+4+5 ... 
- ACM: Gym 101047E Escape from Ayutthaya - BFS
		Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ... 
- 简单明了区分escape、encodeURI和encodeURIComponent
		一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ... 
- c#模拟js escape方法
		public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ... 
- 【BZOJ-1340】Escape逃跑问题      最小割
		1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 264 Solved: 121[Submit] ... 
- LYDSY热身赛 escape
		Description 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行 ... 
- javascript escape()函数和unescape()函数
		javascript escape()函数和unescape()函数 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法: escape(string) stri ... 
- HDU 3605 Escape(状压+最大流)
		Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ... 
随机推荐
- 7.Linux 输入子系统分析
			为什么要引入输入子系统? 在前面我们写了一些简单的字符设备的驱动程序,我们是怎么样打开一个设备并操作的呢? 一般都是在执行应用程序时,open一个特定的设备文件,如:/dev/buttons .... ... 
- Scala——构造函数
			Scala的构造函数分为主构造函数和辅助构造函数. 辅助构造函数 辅助构造函数比较容易理解,它们同C++和Java的构造函数十分类似,只有两处不同: 1.辅助构造函数的名称为this,这主要是考虑到在 ... 
- 阅读笔记——Servlet
			什么是Servlet Servlet是用java编写的运行在web服务器中的程序,因此它可以调用服务器端的类,它也可以被调用,它本身就是一个类. Servlet的工作原理 servlet由web服务器 ... 
- 洛谷——P1073 最优贸易 ([NOIP2009] )
			https://www.luogu.org/problem/show?pid=1073 题目描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多 ... 
- 计科1111-1114班第一次实验作业(NPC问题——回溯算法、聚类分析)
			实验课安排 地点: 科技楼423 时间: 计科3-4班---15周周一上午.周二下午 计科1-2班---15周周一下午.周二晚上(晚上时间从18:30-21:10) 请各班学委在实验课前飞信通知大家 ... 
- [JWT] JWT Signature With RS256 - Learn The Advantages Compared to HS256
			The advantage of RS256 over HS256 is RS256 no longer need to share the secret key between client and ... 
- 一筐梨子&一筐水果——协变性(covariant)
			假设突然看见这个问题.我们常常会想当然. 一个梨子是水果,一筐梨子是一筐水果吗? watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveXFqMjA2NQ==/f ... 
- string-format样式使用
			首先我们看如下代码 protected String calcu1() { StringBuffer resultB = new StringBuffer(); String str = null; ... 
- 【组件】微信小程序input搜索框的实现
			开发小程序的过程,是一个学习知识,解决问题的过程,每当实现了一个需求,总会有很大的成就感,每天记录一个开发过程中的细节.实现效果如下: 官方参考链接:https://developers.weixin ... 
- Jquery+Ajax+Bootstrap Paginator实现分页的拼接
			效果图如下 jsp页面引入bootstrap样式,jquery和bootstrap-paginator.js <link type="text/css" rel=" ... 
