bzoj千題計划294:bzoj3139: [Hnoi2013]比賽


http://www.lydsy.com/JudgeOnline/problem.php?id=3139

 

隊伍的順序不會影響結果

將隊伍的得分情況作為狀態,記憶化搜索

 

就是先搜索第一只隊伍的得分情況,即為他分配分數

當第一只隊伍的分數分配完時,它與其他隊伍的比拼會使其他隊伍也分配到了一定的分數

將其他隊伍分配到的分數 這個狀態 哈希

然后第二支隊……,這就是子問題

 

啊啊啊,我也不知道我在說啥了

 

myl考場AC tql!!!

 

#include<algorithm>
#include<cstring>
#include<cstdio>
#include<map>

#define N 11

using namespace std;

typedef long long LL;

const int mod=1e9+7;

int n,w[N];

map<LL,int>mp[N];

LL gethash(int *b,int p)
{
    LL S=0;
    for(int i=p;i<=n;++i) S=S*28+b[i];
    return S;
}

int dfs(int *val,int l,int r)
{
    if(l==r)
    {
        if(val[l]) return 0;
        if(l==n) return 1;
        int b[N];
        memcpy(b,val,sizeof(b));
        sort(b+l+1,b+n+1);
        LL S=gethash(b,l+1);
        if(mp[l+1].find(S)==mp[l+1].end()) mp[l+1][S]=dfs(b,l+1,n);
        return mp[l+1][S];
    }
    if(3*(r-l)<val[l]) return 0;
    int tot=0;
    if(val[l]>=3)
    {
        val[l]-=3;
        tot+=dfs(val,l,r-1);
        tot-=tot>=mod ? mod : 0;
        val[l]+=3;
    }
    if(val[l] && val[r])
    {
        val[l]--; val[r]--;
        tot+=dfs(val,l,r-1);
        tot-=tot>=mod ? mod : 0;
        val[l]++; val[r]++;
    }
    if(val[r]>=3)
    {
        val[r]-=3;
        tot+=dfs(val,l,r-1);
        tot-=tot>=mod ? mod : 0;
        val[r]+=3;
    }
    return tot;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",&w[i]);
    printf("%d",dfs(w,1,n));
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM