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

请教1037decorative fence(在电脑中测试多组数据通过,包括N = 20,但始终WA)

Posted by weakY at 2009-06-24 23:28:39
#include <iostream>

using namespace std;

typedef long long ll;

ll dp[21][21][2];

int ans[21],digit,realValue[21];

void solve(int N,ll C)
{
	if(N == 1) {ans[digit] = realValue[1];return;}
	ll count = 0,oriCount;
	for(int i = 1;i <= N;i++)
	{
		oriCount = count;
		if(N == digit) count += dp[i][N][0] + dp[i][N][1];
		else if(realValue[i] > ans[digit - N])
		{
			count += dp[i][N][1];
		}
		else{
			count += dp[i][N][0];
		}
		if(count>= C)
		{
			ans[digit - N + 1] = realValue[i];
			for(int j = i;j <= N - 1;j++) realValue[j] = realValue[j + 1];
			solve(N - 1,C - oriCount);
			break;
		}
	}
}

int main()
{

	int K,N;
	ll C;
	memset(dp,0,sizeof(dp));
	int i,j;
	//第三维含义的0指代上升波形开始
	dp[1][1][0] = 1,dp[1][1][1] = 1;
	int index = 1;
	while(++index <= 20)
	{
		for(i = 1;i <= index;i++)
		{
			dp[i][index][0] = 0,dp[i][index][1] = 0;
			for(j = 1;j <= index;j++)
			{
				if(j == i) continue;
				if(j > i) dp[i][index][0] += dp[j - 1][index - 1][1];
				else dp[i][index][1] += dp[j][index - 1][0];
			}
		}
	}
	cin >> K;
	for(i = 0;i < K;i++)
	{
		cin>>N>>C;
		digit = N;
		for(j = 1;j <= 20;j++) realValue[j] = j;
		solve(N,C);
		for(j = 1;j < N;j++) cout<<ans[j]<<" ";
		cout<<ans[N]<<endl;
	}
	return 0;
}

以上程序不知道错在哪里?请高人指教

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