Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

wa了wa了,谁能救救我。!~~~~

Posted by lgq1205 at 2009-08-08 21:05:43 on Problem 1020
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 1000
int col[N];
int re[N];
int a[N];
bool vist[N];
int m,n;
int u;
int mincol;
bool dfs(int cont)
{
	int i;
	if(cont==m)
		return true;
	int min = 10000;
	for(i = 1;i<=n;i++)
		if(min>col[i])
		{
			u = i;
			min = col[i];
		}
	for(i = m;i>=1;i--)
	{
		if(u+a[i] - 1<=n&&min+a[i] - 1 <=n&&!vist[i])
		{
			bool flag = true;
			for(int j = u;j<u+a[i];j++)
				if(col[j]>min)
				{
					flag = false;
					break;
				}
		
			if(flag)
			{
				for(int j = u;j<u+a[i];j++)
					col[j]+=a[i];
				vist[i] = true;

				if(dfs(cont+1)) return true;

				vist[i] = false;
				for(int j = u;j<u+a[i];j++)
					col[j]-=a[i];
			}
		}
	}
	return false;
}
int main()
{
	//freopen("in","r",stdin);
	int t;
	scanf("%d",&t);
	while(t--)
	{
		memset(vist,false,sizeof(vist));
		scanf("%d%d",&n,&m);
		int sum = 0;
		for(int i = 1;i<=m;i++)
		{
			scanf("%d",&a[i]);
			sum+=a[i]*a[i];
		}
		if(sum!=n*n)
		{
			printf("HUTUTU!\n");
			continue;
        }
		sort(a+1,a+m+1);
		fill(col,col+n+1,1);
		if(dfs(0))
		{
			printf("KHOOOOB!\n");
		}
		else printf("HUTUTU!\n");
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator