题意:给你n个人每一个人手里有一个id,然后给你两个数a和b。让你把n个人分为两组。条件是 一组人手里的id和等于a 另一组人的id和等于b,这里的和是指加起来之后对9取余,假设sum等于0 则sum等于9 否则sum = sum。另一种情况也能够
就是全部人的id和等于a 或者等于b 相当于分为一组。

思路:首先 假设能找到满足题意的解。一定满足a和b的和等于n个人的标号的和

然后  数位dp,dp[i][j]表示在第i个数字的时候 前面i个数字能组成j而且包含arr[i]的方案数。

状态转移方程:dp[i][j] = dp[i-1][j] + dp[i-1][cnt],cnt = j - arr[i](这个应该能理解吧),cnt<=0时要加上9;

另外 假设a和b的和不等于n个人的标号的和还要考虑是否满足 a == sum或b == sum;

代码:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <map>
#include <set>
#define sss(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem(a) memset(a,0,sizeof(a))
#define ss(a,b) scanf("%d%d",&a,&b)
#define s(a) scanf("%d",&a)
#define p(a) printf("%d\n", a)
#define INF 0x3f3f3f3f
#define w(a) while(a)
#define PI acos(-1.0)
#define LL long long
#define eps 10E-9
#define N 1000000+20
#define mod 258280327
const int SIGMA_SIZE=26;
const int MAXN=100010;
const int MAXNODE=600010;
using namespace std;
void mys(int& res)
{
int flag=0;
char ch;
while(!(((ch=getchar())>='0'&&ch<='9')||ch=='-'))
if(ch==EOF) res=INF;
if(ch=='-') flag=1;
else if(ch>='0'&&ch<='9') res=ch-'0';
while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0';
res=flag? -res:res;
}
void myp(int a)
{
if(a>9)
myp(a/10);
putchar(a%10+'0');
}
/*************************THE END OF TEMPLATE************************/
int arr[100009];
int dp[100009][10];
int sum_mod(int x, int y){
int ans = x + y;
ans %= 9;
if(!ans) return 9;
return ans;
}
int main(){
int t, n, a, b;
s(t);
w(t--){
mem(dp);
sss(n, a, b);
int sum = 0;
for(int i=1; i<=n; i++){
s(arr[i]);
sum = sum_mod(sum, arr[i]);
}
if(sum != sum_mod(a, b)){
int ans = 0;
if(a == sum) ans ++;
if(b == sum) ans ++;
p(ans % mod);
}
else{
dp[1][arr[1]] = 1;
for(int i=2; i<=n; i++){
for(int j=1; j<=9; j++){
int cnt = j - arr[i] <= 0? j - arr[i] + 9: j-arr[i];
dp[i][j] = (dp[i-1][j] + dp[i-1][cnt]) % mod;
}
}
p((dp[n][a]+dp[n][b])%mod);
}
}
return 0;
}

hdu5389的更多相关文章

  1. 2015 多校联赛 ——HDU5389(dp)

    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 1 ...

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

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

  3. hdu5389(DP)

    题意: 给出n个人的id,有两个门,每一个门有一个标号.我们记作a和b,如今我们要将n个人分成两组,进入两个门中,使得两部分人的标号的和(迭代的求,直至变成一位数.我们姑且叫做求"和&quo ...

  4. hdu5389 Zero Escape

    Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi ...

  5. [hdu5389 Zero Escape]数根的性质,DP

    题意:把n个数(1-9)放到A集合和B集合里面去,使得A集合里面的数的数根为a,B集合里面的数的数根为b,也可以只放在A或B任一个集合里面.求方法总数.比如A={2,4,5},则A的数根为[2+4+5 ...

随机推荐

  1. 测试理论--web测试方法总结

    一.输入框 1.字符型输入框: (1)字符型输入框:英文全角.英文半角.数字.空或者空格.特殊字符“~!@#¥%……&*?[]{}”特别要注意单引号和&符号.禁止直接输入特殊字符时,使 ...

  2. Hadoop-2.6.0上的C的API訪问HDFS

    在通过Hadoop-2.6.0的C的API訪问HDFS的时候,编译和执行出现了不少问题,花费了几天的时间,上网查了好多的资料,最终还是把问题给攻克了 參考文献:http://m.blog.csdn.n ...

  3. Dynamics CRM 2015/2016 Web API:Unbound Custom Action 和 Bound Custom Action

    今天我们再来看看Bound/Unbound Custom Action吧,什么是Custom Action?不知道的小伙伴们就out了,Dynamics CRM 2013就有了这个功能啦.和WhoAm ...

  4. DB2物化视图(Materialized Query Tables, MQT)

    DB2的物化视图MQT是基于查询结果定义的一个表,MQT中包括的数据来自MQT定义所基于的一个或多个表, 使用MQT能够显著提高查询的操作性能. 数据库的视图和MQT都是基于一个查询来定义的.每当视图 ...

  5. 第一个C#控制台程序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. JS实现队列效果,先进先出

    /** * [Queue] * @param {[Int]} size [队列大小] */ function Queue(size) { var list = []; //向队列中添加数据 this. ...

  7. 详解Android插件化开发-资源访问

    动态加载技术(也叫插件化技术),当项目越来越庞大的时候,我们通过插件化开发不仅可以减轻应用的内存和CPU占用,还可以实现热插拔,即在不发布新版本的情况下更新某些模块.     通常我们把安卓资源文件制 ...

  8. CSDN的个人主页如何添加微信二维码

    -–零-– 对于CSDN,这里是技术的交流的地方,有些大神,隐于此.各有各的技能,各有各的魅力. 在这里,如果有自己的能力,你想推广你个人.我想,你将你的微信二维码或者你的微信公众号的二维码放在这里, ...

  9. 00081_List接口

    1.List接口介绍 (1)有序的 collection(也称为序列).此接口的用户可以对列表中每个元素的插入位置进行精确地控制.用户可以根据元素的整数索引(在列表中的位置)访问元素,并搜索列表中的元 ...

  10. 【Codeforces Round #457 (Div. 2) B】Jamie and Binary Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把n分解成二进制的形式. n=2^a0+2^a1+...+2^a[q-1] 则固定就是长度为q的序列. 要想扩展为长为k的序列. 可 ...