Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

11218 - KTV

$
0
0
描述:直接暴就可以了
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define N 100003
int num[1010][4],s[11];
int n,sum,m=1;
void dfs(int cur,int count)
{
    int x=0;
    for(int i=1; i<=9; i++)
        if(!s[i])
        {
            x=1;
            break;
        }
    if(cur>=n||!x)
    {
        if(!x&&count>sum) sum=count;
        return;
    }
    for(int i=cur; i<n; i++)
    {
        if(s[num[i][0]]+s[num[i][1]]+s[num[i][2]]==0)
        {
            s[num[i][0]]=s[num[i][1]]=s[num[i][2]]=1;
            dfs(cur+1,count+num[i][3]);
            s[num[i][0]]=s[num[i][1]]=s[num[i][2]]=0;
        }
    }
}
int main()
{
  //  freopen("a.txt","r",stdin);
    while(scanf("%d",&n)!=EOF)
    {
        if(!n) break;
        sum=-1;
        memset(s,0,sizeof(s));
        for(int i=0; i<n; i++)
            scanf("%d%d%d%d",&num[i][0],&num[i][1],&num[i][2],&num[i][3]);
        dfs(0,0);
        printf("Case %d: %d\n",m++,sum);
    }
    return 0;
}

作者:moyan_min 发表于2013-3-6 11:03:56 原文链接
阅读:24 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>