题目链接

http://acm.hust.edu.cn/vjudge/contest/130883#problem/C

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
 
Recommend
wange2014

题意:输入n,A,B   表示有n个数,一部分放入A中,剩余部分放入B中,或者全放入A中、B中,A中数得满足 和的每一位相加 再对和的每一位求和......直至最后变成一位数,而这个数必须和A相等,B同样如此,求有多少种分配方案?

思路:上述对A中和B中数和的运算  等价于 和对9取余,令A中的和为suma,B中和为sumb,suma+sumb==sum  则suma%9==A   sumb%9==B  所以 如果(suma+sumb)%9==(A+B)%9  且  suma%9==A   那么必有sumb%9==B   所以问题得到简化,先判断(suma+sumb)%9==(A+B)%9  是否成立,若成立,才有可能把n个数分成两部分满足上述条件。    那么在满足的条件下,我们只需算取数放入A中满足条件的方案数,可以用01背包实现;

代码如下:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=;
int a[];
int dp[][]; int main()
{
int T,n,A,B;
cin>>T;
while(T--)
{
int sum=;
scanf("%d%d%d",&n,&A,&B);
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
sum%=;
int res=;
if(sum==B%) res++;
if(sum==(A+B)%)
{
dp[][]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=;j++)
{
if(j>=a[i]) dp[i][j]=dp[i-][j]+dp[i-][j-a[i]];
else dp[i][j]=dp[i-][j]+dp[i-][j+-a[i]];
dp[i][j]%=mod;
}
}
printf("%d\n",(dp[n][A]+res)%mod);
}
else printf("%d\n",(sum==A%)+res);
}
return ;
}

2015暑假多校联合---Zero Escape(变化的01背包)的更多相关文章

  1. 2015暑假多校联合---CRB and His Birthday(01背包)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5410 Problem Description Today is CRB's birthda ...

  2. 2015暑假多校联合---Expression(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5396 Problem Description Teacher Mai has n numb ...

  3. 2015暑假多校联合---Mahjong tree(树上DP 、深搜)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5379 Problem Description Little sun is an artis ...

  4. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  5. 2015暑假多校联合---Friends(dfs枚举)

    原题链接 Problem Description There are n people and m pairs of friends. For every pair of friends, they ...

  6. 2015暑假多校联合---Assignment(优先队列)

    原题链接 Problem Description Tom owns a company and he is the boss. There are n staffs which are numbere ...

  7. 2015暑假多校联合---Problem Killer(暴力)

    原题链接 Problem Description You are a "Problem Killer", you want to solve many problems. Now ...

  8. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  9. 2016暑假多校联合---Windows 10

    2016暑假多校联合---Windows 10(HDU:5802) Problem Description Long long ago, there was an old monk living on ...

随机推荐

  1. PHP-CS-Fixer:格式化你的PHP代码

    简介 良好的代码规范可以提高代码可读性,团队沟通维护成本.最推荐大家遵守的是 php-fig(PHP Framework Interop Group) 组织定义的 PSR-1 . PSR-2 两个.不 ...

  2. 360路由器刷openwrt后设置wifi中继

    上一篇文章(360路由器刷openwrt.不死uboot.双系统 .wifi中继 - 飞鸿影~ - 博客园)讲了如何在360路由器C301上安装openwrt以及安装双系统.这篇文章讲如何设置无线中继 ...

  3. Servlet开发技术,创建,以及Servlet的配置,web.xml的配置

    直接上图,不废话!!! 第一:首先在Eclipse的包资源管理器中,单机鼠标右键,在弹出的快捷键菜单中选择“新建”/Servlet命令,在弹出的对话框中输入新建的Servlet所在的包和类名,然后单击 ...

  4. tabs左右滚动

    $(function () { //IdivLeft小于0,说明左边还有菜单,菜单总数大于8 //IdivLeft等于0,说明菜单总数小于8 //IdivLeft大于0,说明右边还有菜单,菜单总数大于 ...

  5. EasyUI Datagrid Datetime(EasyUI DataGrid 时间格式化)

    EasyUI DataGrid 时间格式化 方法一: var Common = { //EasyUI用DataGrid用日期格式化 TimeFormatter: function (value, re ...

  6. mysql如果数据不存在,则插入新数据,否则更新的实现方法

    mysql如果数据不存在,则插入新数据,否则更新的实现方法 //如果不存在,则插入新数据 $sql = "INSERT INTO {$ecs->table('cat_lang')} ( ...

  7. 在Windows系统搭建.NET Core环境并创建运行ASP.NET网站

    微软于6月27日在红帽DevNation峰会上 正式发布了.NET Core 1.0.ASP.NET 1.0和Entity Framework Core 1.0,其将全部支持Windows.OS X和 ...

  8. 开发工程师面试的秘密( 整理自 Export C Programming )

    开发工程师面试的秘密 因为打算转战linux平台,所以一直在配置自己喜欢的linux操作系统.同时在看那本<C 专家编程>,这本书主要是针对ANSI C 介绍的,所以和Linux(Unix ...

  9. Javascript快速入门(上篇)

    Javascript的熟练之路,小弟来了. JavaScript简介:JavaScript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型.它的解释器被称为JavaScript ...

  10. 使用jasperreports-5.6.0.jar导致的问题

    使用jasperreports-5.6.0.jar导致的问题 Struts2+jasperReport5.6如下设置: <!-- 社员档案 --> <package name=&qu ...