【题目链接】:

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. Sub Thread to update main Thread (UI)

    Sub Thread to update main Thread (UI) main Thread :   A  has Hander.HandleMessage() to process the & ...

  2. Thinkpad Access Connections实现快速的在各种网络间进行切换

    Thinkpad Access Connections快速的在各种网络间进行切换 因为工作的原因要经常在多个无线或有线之间切换,每次要切换到不同的固定IP地址的网络更是一种折磨,换一次就要从新输入一次 ...

  3. python数据处理技巧二

    python数据处理技巧二(掌控时间) 首先简单说下关于时间的介绍其中重点是时间戳的处理,时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00 ...

  4. 2018上半年GitHub上最热门的开源项目

    关注GitHub的人都知道,这个平台上面有太多优秀的值得学习的开源项目了,这里总结了2018上半年GitHub上最热门的开源项目. 1: tensorflow https://github.com/t ...

  5. request中文乱码解决

    String str = new String(request.getParameter("参数名").getBytes("iso-8859-1"), &quo ...

  6. [Python] Manipulate Data with Dictionaries in Python

    Dictionaries may be familiar to you as hash maps. In this lesson, you will learn how to create them, ...

  7. [Python] Find available methods and help in REPL

    For example you want to know what methods are available in Python for String, you can do : dir(" ...

  8. 怎样用redis实现分布式锁

    引子 redis作为一个强大的key/value数据库.事实上还能够用来实现轻量级的分布式锁. 1.实现方案1 最早官方在SETNX命令页给了一个实现: acquire lock: SETNX loc ...

  9. LeetCode Implement strStr()(Sunday算法)

    LeetCode解题之Implement strStr() 原题 实现字符串子串匹配函数strStr(). 假设字符串A是字符串B的子串.则返回A在B中首次出现的地址.否则返回-1. 注意点: - 空 ...

  10. mybatis自己主动生成mapper,dao,映射文件

    一.先创建数据脚本,这里用的mysql数据脚本 drop table VOTE_ITEM; drop table VOTE_OPTION; drop table VOTE_SUBJECT; drop ...