Problem Description
Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (you may hear about ever17?) and developed by Chunsoft.



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.
 
Input
The first line of the input contains a single number T,
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
 
Output
For each test case, output a single integer in a single line, the number of ways that these n players
can get into these two doors.
 
Sample Input
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的更多相关文章

  1. hdu5389 Zero Escape DP+滚动数组 多校联合第八场

    Zero Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

  2. [hdu5389 Zero Escape]数根的性质,DP

    题意:把n个数(1-9)放到A集合和B集合里面去,使得A集合里面的数的数根为a,B集合里面的数的数根为b,也可以只放在A或B任一个集合里面.求方法总数.比如A={2,4,5},则A的数根为[2+4+5 ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. 简单明了区分escape、encodeURI和encodeURIComponent

    一.前言 讲这3个方法区别的文章太多了,但是大部分写的都很绕.本文试图从实践角度去讲这3个方法. 二.escape和它们不是同一类 简单来说,escape是对字符串(string)进行编码(而另外两种 ...

  5. c#模拟js escape方法

    public static string Escape(string s) { StringBuilder sb = new StringBuilder(); byte[] ba = System.T ...

  6. 【BZOJ-1340】Escape逃跑问题 最小割

    1340: [Baltic2007]Escape逃跑问题 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 264  Solved: 121[Submit] ...

  7. LYDSY热身赛 escape

    Description 给出数字N(1<=N<=10000),X(1<=x<=1000),Y(1<=Y<=1000),代表有N个敌人分布一个X行Y列的矩阵上矩形的行 ...

  8. javascript escape()函数和unescape()函数

    javascript escape()函数和unescape()函数 escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串. 语法: escape(string) stri ...

  9. HDU 3605 Escape(状压+最大流)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Sub ...

随机推荐

  1. position记录

    1.  relative(相对定位):生成相对定位的元素,通过top,bottom,left,right的设置相对于其正常(原先本身)位置进行定位.可通过z-index进行层次分级.均是以父级的左上角 ...

  2. mysql集群搭建教程-基础篇

           计算机一级考试系统要用集群,目标是把集群搭建起来,保证一个库dang了,不会影响程序的运行.于是在孟海滨师哥的带领下开始了我的第一次搭建mysql集群,首先看了一些关于集群的资料,然后根 ...

  3. 洛谷——P1781 宇宙总统

    https://www.luogu.org/problem/show?pid=1781 题目背景 宇宙总统竞选 题目描述 地球历公元6036年,全宇宙准备竞选一个最贤能的人当总统,共有n个非凡拔尖的人 ...

  4. 邮件协议与port

          电子邮箱的协议有SMTP.POP2.POP3.IMAP4等.都隶属于TCP/IP协议簇,默认状态下.分别通过TCPport25.110和143建立连接.针对不同的用途和功能,我们在邮件se ...

  5. js进阶 14-9 ajax事件有哪些

    js进阶 14-9 ajax事件有哪些 一.总结 一句话总结:ajax开始时事件.发送时事件,请求完成时事件,请求成功时事件,请求结束时事件,请求错误时事件事件. 1.ajax事件的监听对象是谁? 都 ...

  6. 7. Spring Boot 启动加载数据 CommandLineRunner

    转自:https://blog.csdn.net/catoop/article/details/50501710

  7. chrome 的input 上传响应慢问题解决方案

    <input type="file" accept="image/png,image/jpeg,image/gif" class="form-c ...

  8. BlobTracker

    Blob分析介绍 分类: CV相关2012-11-04 11:25 1929人阅读 评论(5) 收藏 举报 Blob翻译成中文,是“一滴”,“一抹”,“一团”,“弄脏”,“弄错”的意思.在计算机视觉中 ...

  9. 原生js大总结三

    021.定义函数的几种方式   1.关键字函数:function fnName(){};   2.字面量函数:var fn = function(){};   3.构造函数:var fn = new ...

  10. 00091_字符输入流Reader

    1.字符输入流Reader (1)字符输入流Reader我们读取拥有中文的文件时,使用的字节流在读取,那么我们读取到的都是一个一个字节: (2)只要把这些字节去查阅对应的编码表,就能够得到与之对应的字 ...