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

原来gcc也可以用long long ac,错误是因为你的代码中逻辑错误

Posted by InblooM at 2016-09-10 14:45:01 on Problem 1037
#include<stdio.h>
#include<string.h>
int K,N;
int ans[25],visit[25];
long long dp[25][25][2],sum,C;
void pan(int len)
{
	int flag;
	int i,j,k,s;
	for(i=1;i<=N;i++)
	{
		if((dp[i][N][0]+dp[i][N][1])>=sum)
		{
			s=i;
			ans[1]=i;
			break;
		}
		sum-=dp[i][N][0]+dp[i][N][1];
	}
	if(sum<=dp[s][N][1])
		flag=1;
	else
	{
		sum-=dp[s][N][1];
		flag=0;
	}
	int a=2;
	len--;
	while(len)
	{
		if(flag==1)
		{
			for(i=1;i<s;i++)
			{
				if(dp[i][len][0]>=sum)
				{
					s=i;
					ans[a++]=i;
					break;
				}
				sum-=dp[i][len][0];
			}
		}
		if(flag==0)
		{
			for(i=s;i<=len;i++)
			{
				if(dp[i][len][1]>=sum)
				{
					s=i;
					ans[a++]=i;
					break;
				}
				sum-=dp[i][len][1];
			}
		}
		len--;
		flag=1-flag;
	}
	printf("%d",ans[1]);
	visit[ans[1]]=1;
	for(i=2;i<=N;i++)
		for(j=1;j<=N;j++)
		{
			if(visit[j]==0)
			{
				ans[i]--;
				if(ans[i]==0)
				{
					printf(" %d",j);
					visit[j]=1;
					break;
				}
			}
		}
	printf("\n");
}
		
int main()
{
	int i,j,k,x;
	scanf("%d",&K);
	memset(dp,0,sizeof(dp));
	dp[1][1][0]=1;
	dp[1][1][1]=1;
	for(j=2;j<=20;j++)
	{
		for(i=1;i<=j;i++)
		{
			for(x=i;x<=j-1;x++)
				dp[i][j][0]+=dp[x][j-1][1];
			for(x=1;x<i;x++)
				dp[i][j][1]+=dp[x][j-1][0];
		}
	}
	while(K--)
	{
		scanf("%d%lld",&N,&C);
		memset(ans,0,sizeof(ans));
		memset(visit,0,sizeof(visit));
		sum=C;
		pan(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