zoukankan      html  css  js  c++  java
  • [ZJOI2008]生日聚会 BZOJ1037 dp

    题目描述

    今天是hidadz小朋友的生日,她邀请了许多朋友来参加她的生日party。 hidadz带着朋友们来到花园中,打算坐成一排玩游戏。为了游戏不至于无聊,就座的方案应满足如下条件:

    对于任意连续的一段,男孩与女孩的数目之差不超过k。

    很快,小朋友便找到了一种方案坐了下来开始游戏。hidadz的好朋友Susie发现,这样的就座方案其实是很多的,所以大家很快就找到了一种,那么到底有多少种呢?热爱数学的hidadz和她的朋友们开始思考这个问题……

    假设参加party的人中共有n个男孩与m个女孩,你是否能解答Susie和hidadz的疑问呢?由于这个数目可能很多,他们只想知道这个数目除以12345678的余数。

    输入输出格式

    输入格式:

    输入文件party.in仅包含一行共3个整数,分别为男孩数目n, 女孩数目m, 常数k。

    输出格式:

    输出文件party.out应包含一行,为题中要求的答案。

    输入输出样例

    输入样例#1: 复制
    1 2 1
    输出样例#1: 复制
    1

    说明

    对于30%的数据,n , m ≤ 20;

    对于100%的数据, n , m ≤ 150,k ≤ 20。

    设 dp[ i ][ j ][ x ][ y ]表示表示放了i个男生,j个女生,所有后缀中,男生减女生的差最大为x,女生减男生的差最大为y的方案数;

    枚举下一个位置;

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<queue>
    #include<bitset>
    #include<ctime>
    #include<deque>
    #include<stack>
    #include<functional>
    #include<sstream>
    //#include<cctype>
    //#pragma GCC optimize(2)
    using namespace std;
    #define maxn 1000005
    #define inf 0x7fffffff
    //#define INF 1e18
    #define rdint(x) scanf("%d",&x)
    #define rdllt(x) scanf("%lld",&x)
    #define rdult(x) scanf("%lu",&x)
    #define rdlf(x) scanf("%lf",&x)
    #define rdstr(x) scanf("%s",x)
    typedef long long  ll;
    typedef unsigned long long ull;
    typedef unsigned int U;
    #define ms(x) memset((x),0,sizeof(x))
    const long long int mod = 1e9 + 7;
    #define Mod 1000000000
    #define sq(x) (x)*(x)
    #define eps 1e-4
    typedef pair<int, int> pii;
    #define pi acos(-1.0)
    //const int N = 1005;
    #define REP(i,n) for(int i=0;i<(n);i++)
    typedef pair<int, int> pii;
    inline ll rd() {
    	ll x = 0;
    	char c = getchar();
    	bool f = false;
    	while (!isdigit(c)) {
    		if (c == '-') f = true;
    		c = getchar();
    	}
    	while (isdigit(c)) {
    		x = (x << 1) + (x << 3) + (c ^ 48);
    		c = getchar();
    	}
    	return f ? -x : x;
    }
    
    ll gcd(ll a, ll b) {
    	return b == 0 ? a : gcd(b, a%b);
    }
    int sqr(int x) { return x * x; }
    
    
    /*ll ans;
    ll exgcd(ll a, ll b, ll &x, ll &y) {
    	if (!b) {
    		x = 1; y = 0; return a;
    	}
    	ans = exgcd(b, a%b, x, y);
    	ll t = x; x = y; y = t - a / b * y;
    	return ans;
    }
    */
    int n, m, k;
    int dp[200][200][23][23];
    int mode = 12345678;
    
    int main() {
    	//ios::sync_with_stdio(0);
    	cin >> n >> m >> k;
    	dp[0][0][0][0] = 1;
    	for (int i = 0; i <= n; i++) {
    		for (int j = 0; j <= m; j++) {
    			for(int x=0;x<=k;x++)
    				for (int y = 0; y <= k; y++) {
    					if (dp[i][j][x][y]) {
    						int tp = dp[i][j][x][y];
    						(dp[i + 1][j][x + 1][max(y - 1, 0)] += tp) %= mode;
    						(dp[i][j + 1][max(x - 1, 0)][y + 1] += tp) %= mode;
    					}
    				}
    		}
    	}
    	ll res = 0;
    	for (int i = 0; i <= k; i++) {
    		for (int j = 0; j <= k; j++) {
    			res = (res + dp[n][m][i][j]) % mode;
    		}
    	}
    	cout << (ll)res << endl;
    	return 0;
    }
    
    EPFL - Fighting
  • 相关阅读:
    C#重载操作符的那点事
    Winform最小化托盘
    C#多线程传参
    GridView事件大全
    测试2
    测试
    FindFileByContent
    JavaScriptCallCSharp js调用C#属性与方法
    GroupBy
    查询指定属性的文件
  • 原文地址:https://www.cnblogs.com/zxyqzy/p/10290541.html
Copyright © 2011-2022 走看看