Zero Escape

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 864    Accepted Submission(s): 438

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
 
Sample Output
1
0
10
60
 
Author
SXYZ
 
Source
 



   题意:给出n个人的id,有两个门,每一个门有一个标号,我们记作a和b,如今我们要将n个人分成两组。进入两个门中,使得两部分人的标号的和(迭代的求,直至变成一位数)各自等于a和b,问有多少种分法,(能够全部的人进入一个门)。



pid=5389">点击打开链接

pt = j - p[i];

状态转移方程: dp[i][j] = dp[i-1][j] + dp[i-1][pt];

两种处理方法:

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; const int N = 100001;
const int mod = 258280327;
int dp[N][10];
int n,a,b;
int p[N]; int num(int xx,int yy)
{
int t = xx + yy;
if(t%9 == 0)
{
return 9;
}
return t%9;
} int pnum(int xx,int yy)
{
int tt = xx - yy;
if(tt%9 == 0)
{
return 9;
}
if(tt%9<0)
{
return 9+(tt%9);
}
return tt%9;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int sum = 0;
scanf("%d%d%d",&n,&a,&b);
for(int i=1;i<=n;i++)
{
scanf("%d",&p[i]);
sum = num(sum,p[i]);
}
memset(dp,0,sizeof(dp));
dp[0][0] = 1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=9;j++)
{
dp[i][j] += dp[i-1][j];
dp[i][j] = dp[i][j]%mod;
int pt = pnum(j,p[i]);
if(pt == 9)
{
dp[i][j] += max(dp[i-1][0],dp[i-1][9]);
}
else
{
dp[i][j] += dp[i-1][pnum(j,p[i])];
}
dp[i][j] = dp[i][j]%mod;
}
}
int ans = 0;
if(num(a,b) == sum)
{
ans = dp[n][a];
if(a == sum)
{
ans--;
}
}
if(a == sum)
{
ans++;
}
if(b == sum)
{
ans++;
}
printf("%d\n",ans);
}
return 0;
}

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; const int N = 100001;
const int mod = 258280327;
int dp[N][10];
int n,a,b;
int p[N]; int num(int xx,int yy)
{
int t = xx + yy;
if(t%9 == 0)
{
return 9;
}
return t%9;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int sum = 0;
scanf("%d%d%d",&n,&a,&b);
for(int i=1;i<=n;i++)
{
scanf("%d",&p[i]);
sum = num(sum,p[i]);
}
memset(dp,0,sizeof(dp));
dp[0][0] = 1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=9;j++)
{
int pt = num(j,p[i]);
dp[i][j]+=dp[i-1][j];
dp[i][pt]+=dp[i-1][j];
dp[i][j]%=mod;
dp[i][pt]%=mod;
}
}
int ans = 0;
if(num(a,b) == sum)
{
ans = dp[n][a];
if(a == sum)
{
ans--;
}
}
if(a == sum)
{
ans++;
}
if(b == sum)
{
ans++;
}
printf("%d\n",ans);
}
return 0;
}

HDU 5389 Zero Escape(DP + 滚动数组)的更多相关文章

  1. hdu 4576 (简单dp+滚动数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给出1~n的环,m个操作,每次能顺时针或逆时针走w步,询问最后在l~r这段区间内概率.(1 ...

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

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

  3. HDU - 2294 Pendant (DP滚动数组降维+矩阵高速功率)

    Description On Saint Valentine's Day, Alex imagined to present a special pendant to his girl friend ...

  4. hdu 5389 Zero Escape (dp)

    题目:http://acm.hdu.edu.cn/showproblem.php? pid=5389 题意:定义数根:①把每一位上的数字加起来得到一个新的数,②反复①直到得到的数仅仅有1位.给定n,A ...

  5. HDU 1024 Max Sum Plus Plus --- dp+滚动数组

    HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值, ...

  6. HDU 5119 Happy Matt Friends (背包DP + 滚动数组)

    题目链接:HDU 5119 Problem Description Matt has N friends. They are playing a game together. Each of Matt ...

  7. POJ 3666 Making the Grade (DP滚动数组)

    题意:农夫约翰想修一条尽量平缓的路,路的每一段海拔是A[i],修理后是B[i],花费|A[i] – B[i]|,求最小花费.(数据有问题,代码只是单调递增的情况) #include <stdio ...

  8. USACO 2009 Open Grazing2 /// DP+滚动数组oj26223

    题目大意: 输入n,s:n头牛 s个栅栏 输入n头牛的初始位置 改变他们的位置,满足 1.第一头与最后一头的距离尽量大 2.相邻两头牛之间的距离尽量满足 d=(s-1)/(n-1),偏差不超过1 3. ...

  9. hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)

    题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...

随机推荐

  1. CF451E Devu and Flowers (组合数学+容斥)

    题目大意:给你$n$个箱子,每个箱子里有$a_{i}$个花,你最多取$s$个花,求所有取花的方案,$n<=20$,$s<=1e14$,$a_{i}<=1e12$ 容斥入门题目 把取花 ...

  2. Nginx 安装 自用

    hostnamectl set-hostname nginx systemctl stop firewalld.service systemctl disable firewalld.service ...

  3. Edward Frenkel关于几何化朗兰兹纲领的采访

    本文来自:菲尔兹奖座谈会 博客 Edward Frenkel教授的主要研究方向是数学与量子物理中的对称.他现在在做的许多问题都与朗兰兹纲领有关.他现在是加州大学伯克利分校的数学教授. 在今年的菲尔兹奖 ...

  4. find the safest road HDU杭电1596【Dijkstra || SPFA】

    pid=1596">http://acm.hdu.edu.cn/showproblem.php?pid=1596 Problem Description XX星球有非常多城市,每一个城 ...

  5. ITOO右击菜单实现

    ITOO做了持续了这么长时间,client使用MVC+EF+EasyUI框架,服务端在三层基础上增加WCF服务,后来增加容器,AOP(还没怎么接触),封装了在我们刚開始看来神奇的底层方法,克服了非常多 ...

  6. Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 以及 IntelliJ IDEA 怎样打开依赖视图

    Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 配置原则: 利用依赖,将所需的jar包加载到project中. 先依赖主要jar包 Spring + Spring ...

  7. C# 解压及压缩文件源代码

    using System.IO; using System.Windows.Forms; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.Sh ...

  8. js如何实现简繁体互转

    js如何实现简繁体互转 一.总结 一句话总结:其实无论是简体还是繁体,都是在显示端(前端),其实所有的我只用动js就好了,没必要动php. 当然,后端也可以做前端的事情,只是麻烦了点(要多通信两次,第 ...

  9. C# Hook

    C# Hook原理及EasyHook简易教程 前言 在说C# Hook之前,我们先来说说什么是Hook技术.相信大家都接触过外挂,不管是修改游戏客户端的也好,盗取密码的也罢,它们都是如何实现的呢? 实 ...

  10. luogu 1280 尼克的任务

    题目描述 尼克每天上班之前都连接上英特网,接收他的上司发来的邮件,这些邮件包含了尼克主管的部门当天要完成的全部任务,每个任务由一个开始时刻与一个持续时间构成. 尼克的一个工作日为N分钟,从第一分钟开始 ...