题目链接

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. ASP.net的指令

    3.2 ASP.NET指令 在基于面向对象思想的.NET平台,可以称之为“万物皆对象”了.在这里,一个页面,一个用户控件,一个母版页等,全都是对象,全都有各自的属性. 在类文件里,我们表示类的属性可以 ...

  2. Atitit 项目的主体设计与结构文档 v3

    Atitit 项目的主体设计与结构文档 v3 1. 实现的目标2 1.1. cross device跨设备(pc 手机 平板)作为规划2 1.2. 企业级Java体系与开发语言2 1.3. 高扩展性, ...

  3. salesforce 零基础学习(十六)Validation Rules & Date/time

    上一篇介绍的内容为Formula,其中的Date/time部分未指出,此篇主要介绍Date/time部分以及Validation rules. 本篇参考PDF: Date/time:https://r ...

  4. Spring-Context的注解实现依赖注入功能

    使用Spring-Context的注解实现依赖注入功能. Demo要点: 本例子中主要使用Annotation功能来实现对MoviceService的注入.我们将Cinema.java的头部标注为@C ...

  5. Android属性动画之ValueAnimation

    ValueAnimation是ObjectAnimation类的父类,经过前几天的介绍,相信大家对ObjectAnimation有了 一定的认识,今天就为大家最后介绍一下ValueAnimation, ...

  6. Javaweb -- ServletContextListener

    当启动web应用后端服务时,有时需要预先从数据库或者配置文件等读取信息来配置一些全局变量之类的 这时可以用ServletContextListener,在启动服务时,加载设置基本配置 实现如下: (1 ...

  7. 【原创】C#搭建足球赛事资料库与预测平台(6) 赔率数据表设计2

            本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新 开源C#彩票数据资料库系列文章总目录:[目录]C#搭建足球赛事资料库与预测平台与彩票数据分析目录 本篇文章开始将逐步介 ...

  8. bootstrap-datetimepicker.js学习

    之前项目运用到了这个时间控件,期间bug还是一些.抽个时间,简单地看一下. 先看一下datetimepicker.js的结构 var DateTimePicker = function(element ...

  9. 邻接表无向图(二)之 C++详解

    本章是通过C++实现邻接表无向图. 目录 1. 邻接表无向图的介绍 2. 邻接表无向图的代码说明 3. 邻接表无向图的完整源码 转载请注明出处:http://www.cnblogs.com/skywa ...

  10. Android基于mAppWidget实现手绘地图(十五)–如何控制放大缩小

    一般来说,可以使用以下几种方式来控制地图的放大/缩小 : 1. 使用控件底部的缩放按钮 2.双击控件 3.pinch手势 4.物理按键 :I键标识缩小  :O键表示放大.(只有设备具有物理按键才行) ...