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. JavaScript学习总结(5)——Javascript面向(基于)对象编程

    一.澄清概念 1.JS中"基于对象=面向对象" 2.JS中没有类(Class),但是它取了一个新的名字叫"原型对象",因此"类=原型对象" ...

  2. [React] Render Elements Outside the Current React Tree using Portals in React 16

    By default the React Component Tree directly maps to the DOM Tree. In some cases when you have UI el ...

  3. windows下使用cpanm进行模块安装

    windows下使用cpanm进行模块安装 要放假了,突然想整理一下手头上的软件,突然发现perl的安装模块这个功能不能用. 弄了一下,使得windows 下 perl 的 cpanm能用,避免成天为 ...

  4. Quick Sort Algorithm

    快速排序算法实现代码: //============================================================================ // Name : ...

  5. WP8日历(含农历)APP

    WP8日历(含农历)APP WP8日历(含农历)APP UI XAML(部分) <phone:PhoneApplicationPage xmlns:CustomControl="clr ...

  6. Exsi SSH 服务配置

    vi /etc/ssh/sshd_conf禁止口令验证PasswordAuthentication no禁止root登录PermitRootLogin no ESXi Shell F2--F2--Tr ...

  7. Day2:数据类型

    一.数字 1.整型(int),无长整型.python3.x,不论多大的数都是int #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuh ...

  8. StackExchange.Redis 官方文档

    原文:StackExchange.Redis 官方文档 时隔多年的翻译终于完成了第六个,也是很重要的的官方文档,是介绍有关链接管理,管道流水线和多路复用的 官方地址在这里:官方文档 下面做个汇总: S ...

  9. 【2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 G】Query on a string

    [链接]h在这里写链接 [题意] 让你维护字符串的一段区间内T子串的个数. [题解] 因为t不大,所以. 暴力维护一下a[i]就好. a[i]表示的是S串从i位置开始,能和T串匹配几个字符. 用树状数 ...

  10. Virtualizing memory type

    A processor, capable of operation in a host machine, including memory management logic to support a ...