题意:给你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. 新浪新闻按keyword抓取实例

    import urllib2 import requests #import MySQLdb import webbrowser import string import re from Beauti ...

  2. 【v2.x OGE教程 12】 关卡编辑器帮助文档

    ] 关卡编辑器帮助文档 一.简单介绍 关卡编辑器用于游戏关卡界面元素的可视化编辑,包含元素的位置.尺寸以及其他自己定义属性.通过解析生成的数据文件就可以获取关卡信息,并能随时调整.以降低开发工作量,提 ...

  3. [ Javascript ] JavaScript中的定时器(Timer) 是怎样工作的!

    作为入门者来说.了解JavaScript中timer的工作方式是非常重要的.通常它们的表现行为并非那么地直观,而这是由于它们都处在一个单一线程中.让我们先来看一看三个用来创建以及操作timer的函数. ...

  4. webgoat 7.1 实战指南

    WSASP中文文档参考链接: http://www.owasp.org.cn/owasp-project/2017-owasp-top-10 OWASP Top 10 2017中文版V1.3http: ...

  5. Index was out of range

    Index was out of range. Must be non-negative and less than the size of the collection. Parameter nam ...

  6. mybatis在XML中大于号转义字符

    mybatis在编写sql时不能在XML里直接使用‘<’ 或者是 ‘>’ 在这里需要使用转义字符替换 下面列举常用的xml转义对应: * <           <       ...

  7. ZJOI2017线段树

    ZJOI2017线段树 题意: ​ 给你一颗广义线段树,太长了,自己去看. 题解: ​ 直接上zkw那一套,把闭区间换成开区间,就是把取\([l,r]\),变成取\([l-1,l-1],[r+1,r+ ...

  8. WPF框架ZFS

    前文 项目开源地址(非正式版,开发版本), 码云Gitee地址:  https://gitee.com/zhgg666/publicWpf XAML XAML能帮助团队真正实现UI与逻辑的剥离.XAM ...

  9. netstat -p 显示 -

    http://4735839.blog.51cto.com/4725839/1418945 https://yq.aliyun.com/articles/63060

  10. Android eclipse 提示java代码 快捷键

    1.提示java代码能够用ALT+/ 键就能够了(前提是你要把你须要的类或方法的首字母打出来).我添加的部分:仅仅要输入sysout,然后alt+/键就能够输出System.out.prinln(), ...