1 条题解

  • 0
    @ 2026-7-4 11:20:08

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <map>
    using namespace std;
    const int MOD = 1e9+7;
    #define int long long 
    int read()
    {
    	int x=0,f=1;char c;
    	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
    	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
    	return x*f;
    }
    int n,sum,nx,ny,a[15],c[15];map<int,int> mp;
    int dfs(int x,int y)
    {
    	if(x==n) return 1;
    	if(a[x]+3*(n-y+1)<c[x]) return 0;
    	if(y==n+1)
    	{
    		int b[15]={},s=0;
    		for(int i=x+1;i<=n;i++) b[i]=c[i]-a[i];
    		sort(b+1,b+1+n);
    		for(int i=x+1;i<=n;i++) s=30*s+b[i]+1;
    		if(mp.find(s)!=mp.end()) return mp[s];
    		return mp[s]=dfs(x+1,x+2);
    	}
    	int ans=0;
    	if(a[x]+3<=c[x] && nx)//win
    	{
    		a[x]+=3;nx--;
    		ans+=dfs(x,y+1);
    		a[x]-=3;nx++;
    	}
    	if(a[y]+3<=c[y] && nx)//lose
    	{
    		a[y]+=3;nx--;
    		ans+=dfs(x,y+1);
    		a[y]-=3;nx++;
    	}
    	if(a[x]+1<=c[x] && a[y]+1<=c[y] && ny)
    	{
    		a[x]++;a[y]++;ny--;
    		ans+=dfs(x,y+1);
    		a[x]--;a[y]--;ny++;
    	}
    	return ans%MOD;
    }
    signed main()
    {
    	n=read();
    	for(int i=1;i<=n;i++)
    		c[i]=read(),sum+=c[i];
    	sort(c+1,c+1+n);
    	nx=sum-n*(n-1);ny=n*(n-1)/2-nx;
    	printf("%lld\n",dfs(1,2)%MOD);
    }
    
    
    • 1

    信息

    ID
    4804
    时间
    2000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    19
    已通过
    6
    上传者