| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
帮忙看一下,过了samples,但总是WA,C++ 方式提交#include <stdio.h>
#define allTime 420
int arr[20][20];
int flag[20];
int stayTime[20];
int calTime;
int iCount;
int bestCount=0;
int arrBest[20];
int iTag;
int N;
void calculateCount(int last)
{
for(int i=0;i<N;i++)
{
if(flag[i]==0)
{
/////calculate
calTime = calTime+ arr[last][i] + stayTime[i];
if(calTime<=allTime)
{
if(++iCount==N)
{
bestCount = iCount;
return;
}
else
{
if(iCount>bestCount)
{
bestCount = iCount;
}
flag[i]=1;
calculateCount(i);
flag[i]=0;
if(bestCount==N)
{
return;
}
}
}
else
{
calTime =calTime- arr[last][i] - stayTime[i];
return;
}
}
}
}
int main()
{
//read the data
iTag=0;
while(1)
{
scanf("%d",&N);
if(N==0) break;
int i;
int j;
for(i=0;i<N;i++)
{
scanf("%d",&stayTime[i]);
}
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
scanf("%d",&arr[i][j]);
}
}
///init
for(i=0;i<N;i++)
{
flag[i]=0;
}
///calculate a round
for(i=0;i<N;i++)
{
iCount=0;
calTime=0;
if(stayTime[i]>=420)
{
bestCount=0;
continue;
}
else
{
bestCount=1;
calTime=stayTime[i];
iCount=1;
flag[i]=1;
calculateCount(i);
if(bestCount==N)
{
break;
}
flag[i]=0;
}
}
//printf("%d\n",bestCount);
arrBest[iTag] = bestCount;
iTag++;
///end a round
}
for(int k=0;k<iTag;k++)
{
printf("%d\n",arrBest[k]);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator