标签:acm算法 algorithm amp iostream namespace
input | output |
---|---|
5 10 0 |
3 4 |
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define MAXN 100000 int a[MAXN]; int sum[MAXN]; int main() { int i; int ans=3; a[0]=0; a[1]=1; a[2]=1; a[3]=2; a[4]=1; a[5]=3; sum[0]=0; sum[1]=1; sum[2]=1; sum[3]=2; sum[4]=2; sum[5]=3; for(i=6; i<100000; i++) { if(i&1) a[i]=a[i/2]+a[i/2+1]; else a[i]=a[i/2]; ans=max(ans,a[i]); sum[i]=ans; } int n; while(cin>>n,n) cout<<sum[n]<<endl; return 0; }
标签:acm算法 algorithm amp iostream namespace
原文地址:http://blog.csdn.net/sky_miange/article/details/45507481