首页 > 其他 > 详细

BZOJ 1037 生日聚会(神DP)

时间:2017-03-03 22:12:15      阅读:204      评论:0      收藏:0      [点我收藏+]

这题的DP很难想,定义dp[i][j][a][b]表示用了i个男生,j个女生,任一连续的后缀区间内,男生比女生最多多a人,女生比男生最多多b人。

转移就是显然了。

 

技术分享
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-9
# define MOD 12345678
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
    int res=0, flag=0;
    char ch;
    if((ch=getchar())==-) flag=1;
    else if(ch>=0&&ch<=9) res=ch-0;
    while((ch=getchar())>=0&&ch<=9)  res=res*10+(ch-0);
    return flag?-res:res;
}
void Out(int a) {
    if(a<0) {putchar(-); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+0);
}
const int N=10005;
//Code begin...

int dp[155][155][25][25];

int main ()
{
    int n, m, k;
    scanf("%d%d%d",&n,&m,&k);
    dp[0][0][0][0]=1;
    FOR(i,0,n) FOR(j,0,m) FOR(l1,0,k) FOR(l2,0,k) {
        dp[i+1][j][l1+1][max(l2-1,0)]=(dp[i+1][j][l1+1][max(l2-1,0)]+dp[i][j][l1][l2])%MOD;
        dp[i][j+1][max(l1-1,0)][l2+1]=(dp[i][j+1][max(l1-1,0)][l2+1]+dp[i][j][l1][l2])%MOD;
    }
    int ans=0;
    FOR(i,0,k) FOR(j,0,k) ans=(ans+dp[n][m][i][j])%MOD;
    printf("%d\n",ans);
    return 0;
}
View Code

 

BZOJ 1037 生日聚会(神DP)

原文:http://www.cnblogs.com/lishiyao/p/6498445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!