【题目链接】:

pid=5389">click here~~

【题目大意】:

题意:

给出n个人的id,有两个门,每一个门有一个标号,我们记作a和b,如今我们要将n个人分成两组,进入两个门中,使得两部分人的标号的和(迭代的求。直至变成一位数,我们姑且叫做求“和”操作~)各自等于a和b,问有多少种分法。

【思路】:比赛的时候还是学弟递推的方程。当时是dp三维dp[i][j]k]:分别表示枚举到第i位,A门。B门的状态,可是一直没想到怎么进一步优化,卡在100n的复杂度了

赛后看了一下题解,(尽管高中生写的题解看了好像也没什么卵用~~)发现事实上能够用二维数组解决啊,仅仅要计算全部读入数组的和,和A。B门的比較一下。相等是时候进一步枚举j,否则直接推断和A,B门相等的情况,ans++,最后答案就是ans了,还是太弱了。加油吧!T_T!

代码:

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stack>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#define eps 0.00000001
#define pi acos(-1,0)
#define pr 999983
using namespace std;
typedef long long LL;
const int MOD=258280327;
int arr[110000]= {0};
int dp[110000][10]= {0}; inline LL read()
{
int c=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){c=c*10+ch-'0';ch=getchar();}
return c*f;
} LL get(LL n){return (n-1)%9+1;} int main(){
LL t,n,A,B;
t=read();
while(t--){
LL sum=0;
LL ans=0;
memset(dp,0,sizeof(dp));
memset(arr,0,sizeof(arr));
n=read();A=read();B=read();
for(int i=1; i<=n; ++i){ /// get the sum of arr[i]
arr[i]=read();
arr[i]=get(arr[i]);
sum+=arr[i];
}
sum=get(sum);
LL xx=get(A+B); /// judge the sum and xx
if(sum==xx){
dp[1][arr[1]]=1; /// dp[i][j]: 枚举到第i位和为j的方案数
for(int i=2; i<=n; ++i){
for(int j=1; j<=9; ++j){
int k=j-arr[i];
if(k<=0) k+=9;
dp[i][j]=(dp[i-1][k]+dp[i-1][j])%MOD;
}
}
ans=(dp[n][A]+dp[n][B])%MOD;
printf("%lld\n",ans);
}
else{
if(sum==A) ans++;
if(sum==B) ans++;
printf("%lld\n",ans%MOD);
}
} return 0;
} /*
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
*/

HDU 5389 Zero Escape (MUT#8 dp优化)的更多相关文章

  1. HDU 5389 Zero Escape(dp啊 多校)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5389 Problem Description Zero Escape, is a visual no ...

  2. hdu 5389 Zero Escape (dp)

    题目:http://acm.hdu.edu.cn/showproblem.php? pid=5389 题意:定义数根:①把每一位上的数字加起来得到一个新的数,②反复①直到得到的数仅仅有1位.给定n,A ...

  3. HDU 5389 Zero Escape(DP + 滚动数组)

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

  4. hdu 4734 F(x)(数位dp+优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 题意:我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2 ...

  5. hdu 3336 Count the string KMP+DP优化

    Count the string Problem Description It is well known that AekdyCoin is good at string problems as w ...

  6. hdu 5389 Zero Escape(记忆化搜索)

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

  7. 2015 Multi-University Training Contest 8 hdu 5389 Zero Escape

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

  8. HDU 5389 Zero Escape

    题意:有一些人,每人拿一个号码,有两个门,门的值分别为A和B,要求把人分成两堆(可以为空)一堆人手持号码之和的数字根若等于A或者B就可以进入A门或者B门,要求两堆人分别进入不同的门,求有几种分配方式, ...

  9. 递推DP HDOJ 5389 Zero Escape

    题目传送门 /* 题意:把N个数分成两组,一组加起来是A,一组加起来是B,1<=A,B<=9,也可以全分到同一组.其中加是按照他给的规则加,就是一位一位加,超过一位数了再拆分成一位一位加. ...

随机推荐

  1. 【引用】Android程序实现完全退出

    这是我在网上找到的,方法不错,都能够实现程序的完全退出http://www.jb51.net/article/37992.htm

  2. Python(七) 高级部分:面向对象

    一.类的定义 # 面向对象 #有意义的面向对象代码 # 类 = 面向对象 # 类.对象 #实例化 # 类最基本的作用:封装 class Student(): name = '' age = 0 def ...

  3. 关于springmvc重定向后Cannot create a session after the response has been committed问题

    首先先上代码吧,我在用springmvc进行response.sendRedirect(url);操作后报了Cannot create a session after the response has ...

  4. Linux Cgroups

    目录 Linux Cgroups Cgroups中的三个组件 三个组件的关系 Kernel接口 Docker是如何使用Cgroups的 Go语言实现Cgroups限制容器资源 Linux Cgroup ...

  5. 重大漏洞:Bitlocker成摆设,多款固态硬盘硬件加密均可被绕过

    荷兰拉德堡德大学的两名研究人员日前发表论文,描述了固态硬盘流行加密软件Bitlocker中的关键漏洞.固态硬盘需要口令来加密和解密其上存储的内容,但该口令可以被绕过. 荷兰拉德堡德大学的两名研究人员日 ...

  6. cogs 1456. [UVa 10881,Piotr's Ants]蚂蚁

    1456. [UVa 10881,Piotr's Ants]蚂蚁 ★   输入文件:Ants.in   输出文件:Ants.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述 ...

  7. I帧、P帧和B帧的特点

    I帧:帧内编码帧 I帧特点: 1.它是一个全帧压缩编码帧.它将全帧图像信息进行JPEG压缩编码及传输; 2.解码时仅用I帧的数据就可重构完整图像; 3.I帧描写叙述了图像背景和运动主体的详情; 4.I ...

  8. mysql异常Lock wait timeout exceeded; try restarting transaction

    mysql中使用update语句更新数据报错: Lock wait timeout exceeded; try restarting transaction. 这是由于你要更新的表的锁在其它线程手里. ...

  9. windows10系统下设置mtu值的方法

     windows10系统下设置mtu值的方法 http://www.xitongcheng.com/jiaocheng/win10_article_34701.html 以下为服务器上使用  ip ...

  10. 33.IDEA + maven]在IDEA中打开一个maven项目,resolve完依赖后,缺少部分jar包问题

    转自:https://www.cnblogs.com/zazalu/p/7649590.html [注意]作者只是对使用过程中遇到的问题提出了一个解决方案,但是本人在编写此解决方案文章的时候,对mav ...