HDU5389.Zero Escape
来源:互联网 发布:linux sudo命令详解 编辑:程序博客网 时间:2024/05/20 16:43
思路:
发现一个数的数字根只和它mod 9之后的值有关,只要类似背包就能完成人员分配的计算。
首先可以求出其全部的数%9之后的值,
如果(door1+door2)%9==sum%9的话,证明这些数可以分别存到两个不同的门中,否则的话输出0或1(这种情况比较简单,这里就不一一阐述了)
当能正好被分配到两个门中时,考虑如果sum==door&&sum==door2时,应该给答案加1,因为dp[n][sum]只记录了一次全部放在一个门中的情况
我还考虑了特殊的情况,因为比如
7 9 7
1 1 1 1 1 1 1
这种情况dp[n][door1]是为0的,而dp[n][door2]不为0,
平常的情况应该是dp[n][door2]=dp[n][door1]
#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <ctime>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f#define inf -0x3f3f3f3f#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define mem0(a) memset(a,0,sizeof(a))#define mem1(a) memset(a,-1,sizeof(a))#define mem(a, b) memset(a, b, sizeof(a))typedef long long ll;const int maxn=1e5;const __int64 MOD = 258280327;__int64 dp[maxn][11];int a[maxn];__int64 ans;int main(){ int t; int sum,n; int door1,door2; scanf("%d",&t); while(t--){ sum=0; scanf("%d%d%d",&n,&door1,&door2); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); sum=(sum+a[i])%9; } if(sum==0) sum=9; mem0(dp); for(int i=1;i<=n;i++){ for(int j=1;j<=9;j++){ int tmp=(j+9-a[i])%9; //tmp+a[i]构成j if(tmp==0) tmp=9; dp[i][j]=dp[i-1][tmp]+dp[i-1][j]; if(j==a[i]) //由自己本身一个数构成 dp[i][j]++; dp[i][j]%=MOD; } } int mod=(door1+door2)%9; if(mod==0) mod=9; if(sum==mod){ __int64 ans=0; if(sum==door1&&sum==door2) ans+=1; printf("%I64d\n",(max(dp[n][door1],dp[n][door2])+ans)%MOD); } else{ __int64 ans=0; if(sum==door1){ ans+=1; } else if(sum==door2){ ans+=1; } printf("%I64d\n",ans); } } return 0;}
0 0
- HDU5389.Zero Escape
- hdu5389 Zero Escape
- hdu5389 Zero Escape
- hdu5389 Zero Escape(动态规划)
- hdu5389 Zero Escape(DP)
- HDU5389:Zero Escape(dp & 类背包)
- hdu5389 Zero Escape(模拟+找规律+DP)
- hdu5389(2015多校8)--Zero Escape(dp)
- hdu5389 Zero Escape DP+滚动数组 多校联合第八场
- hdu5389
- hdu5389
- HDU5389
- hdu 5389 Zero Escape
- HDU 5389 Zero Escape
- 【HDOJ 5389】 Zero Escape
- HDU 5389 Zero Escape
- hdu 5389 Zero Escape
- HDU 5389 Zero Escape
- ZOJ 3469 Food Delivery
- C++ STL::bitset
- C++字符串string类提供的处理字符串的函数
- 自动装箱拆箱
- android theme ActionBar
- HDU5389.Zero Escape
- 黑马程序员-----------C语言基础-----------数组
- 可修改主席树
- Linux C编程的DEBUG宏
- hdu 5385 The path
- 【POJ 1260】Pearls
- 如何快速将vc++的类转换为c#/cli
- JSON格式注册登录查询byHttpClientDoPost
- gcc简单命令记录