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 |
未知复杂度DP 飘过~#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator