zoj 3149 Breadtree
来源:互联网 发布:画立体图的软件 编辑:程序博客网 时间:2024/05/22 15:23
Description
Breadtree is a kind of tree that produces bread. At its first year, a breadtree is only a node with a bread of weight 0 on this node which is also called zeronode. Every year after that, the weight of bread on each node of the tree will increase by 1, and another branch with a zeronode will grow at the end of each node. However, there is a limit of branches on each node. That is, when the number of branches of a node reaches the limit, there won't be any more branches, but the weight of its bread will still increase. What's more, a breadtree remains unchanged when the total weight of bread is larger than 1234567890.
Input
There are two integers N and K on each line. N is a positive integer fit in signed 32-bit integer. K is a non-negative integer fit in signed 32-bit integer. An N equals to 0 signals the end of input, which should not be processed.
Output
Output the total weight of bread on a breadtree with branches limit K in the N-th year in a line for each case.
Sample Input
10000 0101 110 21221 1280 0
Sample Output
999950502212147483647
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <map>#include <stack>#include <vector>#include <set>#include <queue>#pragma comment (linker,"/STACK:102400000,102400000")#define maxn 100005#define MAXN 16005#define mod 1000000000#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6typedef long long ll;using namespace std;ll n,m,k,ans,cnt,tot,flag;ll dp[maxn],sum[maxn];ll xx=1234567890;ll solve(){ ll i,j,d,t; dp[0]=sum[0]=0; for(i=1;i<=n;i++) { dp[i]=i+sum[i-1]-sum[max(0LL,i-k-1)]; sum[i]=sum[i-1]+dp[i]; if(dp[i]>xx) return dp[i]; } return dp[n];}int main(){ ll i,j,t; while(scanf("%lld%lld",&n,&k),n|k) { n--; if(k==0) { printf("%lld\n",min(n,xx+1)); continue ; } ans=solve(); printf("%lld\n",ans); } return 0;}/*10000 0101 110 21221 1280 0*/
- ZOJ 3149 Breadtree DP
- zoj 3149 Breadtree
- zoj 3149 Breadtree(朴素DP)
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- 关于冒泡排序算法的几种实现
- 【C++】浙大PAT (Basic Level)1011. A+B和C (15)
- linux mysql 创建一个新用户以及设权限密码
- java中的函数
- 找第一个只出现一次的字符
- zoj 3149 Breadtree
- ADT/Eclipse上 使用SVN管理项目基本流程 一看就懂
- oracle USEREVN()用法
- robotium 相关参数备份
- Web Design Mastery - Professional Web Site Design Made Easy
- VS2010 C++中调试DLL工程
- 如何使用CeLog调试Windows mobile设备驱动
- Junit 断言方法
- 动态链接库管理