2021辽宁省赛 E.生活大爆炸(计数dp)

题意:

2021辽宁省赛 E.生活大爆炸(计数dp)_第1张图片

解法:
由于数据范围较小,我选择直接无脑上dp.

令d[i][p][j][k]表示前i个人,选了个,其中有j个男生,k个女生的方案数,
由于只需要满足j>=4和k>=1即可,因此j和k这一维只需要开到41就行了.

复杂度O(60*60*5*2)
code:
#include
// #define SYNC_OFF
typedef std::vector<int> VE;
typedef std::pair<int,int> PI;
#define int long long
#define ll long long
#define ull unsigned long long
//fast-coding
#define ST(x) x.begin()
#define ED(x) x.end()
#define RST(x) x.rbegin()
#define RED(x) x.end()
#define CL(x) x.clear();
#define all(a,n) a+1,a+1+n
#define ff(i,n) for(ll i=1;i<=n;i++)
#define rff(i,n) for(ll i=n;i>=1;i--)
#define fff(i,n) for(ll i=0;i<n;i++)
#define rfff(i,n) for(ll i=n-1;i>=0;i--)
#define SC(x) scanf("%s",x)
#define SL(x) strlen(x)
#define pss(a) push_back(a)
#define ps(a) push(a)
#define SZ(x) (int)x.size()
#define pee puts("");
#define eee putchar(' ');
#define re readdd()
#define pr(a) printtt(a)
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;//
if(x>=10)printtt(x/10);putchar(x%10+'0');}
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
bool addd(int a,int b){return a>b;}
int lowbit(int x){return x&-x;}
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
bool isdigit(char c){return c>='0'&&c<='9';}
bool Isprime(int x){
    for(int i=2;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
void ac(int x){if(x)puts("YES");else puts("NO");}
//
using namespace std;
// const int mod=998244353;
const int mod=1e9+7;
const int maxm=2e6+5;
int d[66][66][5][2];
int a[66];
int n,m,t;
void solve(){
    n=re,m=re,t=re;
    ff(i,n)a[i]=1;
    ff(i,m)a[i+n]=0;
    d[0][0][0][0]=1;
    for(int i=0;i<n+m;i++){
        for(int p=0;p<=t;p++){
            for(int j=0;j<5;j++){
                for(int k=0;k<2;k++){
                    if(!d[i][p][j][k])continue;
                    //不选
                    d[i+1][p][j][k]+=d[i][p][j][k];
                    //选
                    if(p+1>t)continue;
                    if(a[i+1]){//男
                        int nt=min(j+1,4LL);
                        d[i+1][p+1][nt][k]+=max(d[i+1][p+1][nt][k],d[i][p][j][k]);
                    }else{//女
                        int nt=min(k+1,1LL);
                        d[i+1][p+1][j][nt]+=max(d[i+1][p+1][j][nt],d[i][p][j][k]);
                    }
                }
            }
        }
    }
    int ans=d[n+m][t][4][1];
    pr(ans);
}
void Main(){
    // #define MULTI_CASE
    #ifdef MULTI_CASE
    int T;cin>>T;while(T--)
    #endif
    solve();
}
void Init(){
    #ifdef SYNC_OFF
    ios::sync_with_stdio(0);cin.tie(0);
    #endif
    #ifndef ONLINE_JUDGE
    freopen("../in.txt","r",stdin);
    freopen("../out.txt","w",stdout);
    #endif
}
signed main(){
    Init();
    Main();
    return 0;
}

你可能感兴趣的:(1024程序员节)