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

未知复杂度DP 飘过~

Posted by proverbs at 2012-10-07 13:07:51 on Problem 1844
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

bool dp[2][200001];
int n;

void prev()
{
	n+=100000;
	memset(dp[0],0,sizeof dp[0]);
	dp[0][100000]=true;
	for(int i=1;;i++)
	{
		memset(dp[i&1],0,sizeof dp[i&1]);
		for(int j=0;j<=200000;j++)
		{
			if(dp[(i-1)&1][j])
			{
				if(j+i<=200000) dp[i&1][j+i]=true;
				if(j-i>=0) dp[i&1][j-i]=true;
			}
		}
		if(dp[i&1][n]) {printf("%d\n",i);return;}
	}
}

int main()
{
	while(scanf("%d",&n)!=EOF) prev();
	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