ZOJ 3149 Breadtree DP

--------------------

const int maxn=100000;
const int maxm=10000;
const LL LIM=1234567890LL;
LL n,k;
LL f[maxn];
LL sum[maxn];
int main(){
    while (cin>>n>>k){
        if (n==0) break;
        if (k==0) cout<<min(LIM+1,n-1)<<endl;
        else{
            f[0]=0;
            LL ans=0;
            sum[0]=0;
            for (LL i=1;i<n;i++){
                f[i]=i+sum[i-1]-sum[max(i-k-1,0LL)];
                sum[i]=sum[i-1]+f[i];
                ans=f[i];
                if (f[i]>LIM) break;
            }
            cout<<ans<<endl;
        }
    }
	return 0;
}


--------------------

posted on 2014-01-12 22:30  电子幼体  阅读(138)  评论(0编辑  收藏  举报

导航