题目链接

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. java初学者应掌握的30个基本概念

    核心提示:OOP中唯一关系的是对象的接口是什么,就像计算机的销售商她不管电源内部结构 是怎样的,他只关系能否给你提供电就行了,也就是只要知道can or not而不是how and why. 基本概念 ...

  2. Drupal网站开发实践--自定义购物流程

    由于Commerce模块自带的购物流程步骤过多,界面不太美观,所以需要重新设计. 改造后的购物流程分成两部:购物车->结算,就两个页面.购物车页面可以修改商品的数量,删除购物车内商品,查看总金额 ...

  3. iOS-数据持久化-偏好设置

    一.简单介绍 很多iOS应用都支持偏好设置,比如保存用户名.密码.字体大小等设置,iOS提供了一套标准的解决方案来为应用加入偏好设置功能 每个应用都有个NSUserDefaults实例,通过它来存取偏 ...

  4. Jenkins+MSbuild+SVN实现dotnet持续集成 快速搭建持续集成环境

    Jenkins是一个可扩展的持续集成引擎,Jenkins非常易于安装和配置,简单易用,下面开始搭建dotnet持续集成环境 一.准备工作 1.系统管理-->管理插件-->可选插件中找到MS ...

  5. 静态(static)代码块、构造代码块、构造函数、父类子类执行顺序

    静态代码块:static修饰的代码块. 在类加载-初始化的时候进行,主要目的是给变量赋予初始值 构造代码块:直接在类中定义且没有加static关键字的代码块称为构造代码块. java会把构造代码块放到 ...

  6. Lua 学习笔记(二)语法、类型、值

    首先Lua执行的每一段代码都称之为“程序块”,一个程序块也就是一连串的语句或命令,例如一个源码文件或一行代码.Lua语句之间并不需要分隔符,如代码中的换行就不起任何作用,当然为了养成编码习惯当两条或者 ...

  7. MongoDB的学习--explain()和hint()

    Explain 从之前的文章中,我们可以知道explain()能够提供大量与查询相关的信息.对于速度比较慢的查询来说,这是最重要的诊断工具之一.通过查看一个查询的explain()输出信息,可以知道查 ...

  8. 【知识积累】DES算法之C#加密&Java解密

    一.前言 在项目需要添加安全模块,客户端调用服务端发布的service必须要经过验证,加密算法采用DES,客户端采用C#进行加密,服务端使用Java进行解密.废话不多说,直接上代码. 二.客户端 客户 ...

  9. Windows Azure Web Site (16) Azure Web Site HTTPS

    <Windows Azure Platform 系列文章目录> 我们在使用微软云Azure Web App的时候,会使用微软的二级域名:http://xxx.chinacloudsites ...

  10. SQL Server存储(6/8) :理解DCM页

    我们已经讨论了各种不同的页,包括数据页.GAM与SGAM页.PFS页,还有IAM页.今天我们来看下差异变更页(Differential Change Map:DCM ),还有差异备份(differen ...