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

    题解:

    我们设dp[a][b][c][d]表示目前已经有a个男生,b个女生,在某一时刻男生最多比女生多c个,在某一时刻女生最多比男生多d个.
    所以就可以转移了:
    (dp[a+1][b][c+1][max(d-1,0)]+=dp[a][b][c][d])%=mod;
    (dp[a][b+1][max(c-1,0)][d+1]+=dp[a][b][c][d])%=mod;

     1 #include<iostream>
     2 #include<cstdlib>
     3 #include<cstdio>
     4 #include<cmath>
     5 #include<algorithm>
     6 #include<cstring>
     7 #include<queue>
     8 #include<vector>
     9 #include<set>
    10 #define MAXN 500010
    11 #define RG register
    12 #define LL long long int
    13 using namespace std;
    14 const int INF=1e9;
    15 const int mod=12345678;
    16 int n,m,k;
    17 LL dp[155][155][25][25];
    18 LL ans;
    19 int main()
    20 {
    21   freopen("1.in","r",stdin);
    22   scanf("%d%d%d",&n,&m,&k);
    23   dp[0][0][0][0]=1;
    24   for(int a=0;a<=n;a++)
    25     for(int b=0;b<=m;b++)
    26       for(int c=0;c<=k;c++)
    27     for(int d=0;d<=k;d++)
    28       {
    29         (dp[a+1][b][c+1][max(d-1,0)]+=dp[a][b][c][d])%=mod;
    30         (dp[a][b+1][max(c-1,0)][d+1]+=dp[a][b][c][d])%=mod;
    31       }
    32   for(int c=0;c<=k;c++)
    33     for(int d=0;d<=k;d++)
    34       (ans+=dp[n][m][c][d])%=mod;
    35   printf("%lld
    ",ans);
    36   return 0;
    37 }
  • 相关阅读:
    62. Unique Paths
    24. Swap Nodes in Pairs
    83. Remove Duplicates from Sorted List
    21. Merge Two Sorted Lists
    141. Linked List Cycle
    268. Missing Number
    191. Number of 1 Bits
    231. Power of Two
    9. Palindrome Number
    88. Merge Sorted Array
  • 原文地址:https://www.cnblogs.com/Landlord-greatly/p/8082624.html
Copyright © 2011-2022 走看看