NYOJ Cut the rope

Cut the rope

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 4
 

描述

 

We have a rope whose length is L. We will cut the rope into two or more parts, the length of each part must be an integer, and no two parts have the same length.
  Your task is to calculate there exists how many results after the cutting. We say two results are different if and only if there is at least one part, which we can find in one result but can not find in the other result

 

输入

There is an integer T (1 <= T <= 50000) in the first line, which indicates there are T test cases in total.
  For each test case, there is only one integer L (1 <= L <= 50000) which has the same meaning as above.

输出

For each test case, you should output the correct answer of the above task in one line.
  Because the answer may be very large, you should just output the remainder of it divided by 1000000 instead

样例输入

3
2
3
6

样例输出

0
1
3

上传者

 

动态规划,dp[i][j]表示i分解陈j个数的数量,

dp[i][j]=dp[i-j][j](不包含1)+dp[i-j][j-1](包含1);

 

AC代码:

 

 

# include <cstdio>
# include <cstring>
# include <cmath>
# include <cstdlib>
using namespace std;
const int mod=1000000;
int dp[50010][320];
int main(){
	int n, t, i, j, k, sum;
	memset(dp, 0, sizeof(dp));
	dp[3][2]=1;dp[4][2]=1;
	dp[5][2]=2;dp[6][2]=2;dp[6][3]=1;
	for(i=1; i<=50000; i++){
		dp[i][1]=1;
	}
	for(i=7; i<=50000; i++){
		for(j=2; j*(j+1)/2<=i; j++){
			dp[i][j]=(dp[i-j][j]+dp[i-j][j-1])%mod;
		}
	}
	scanf("%d", &t);
	for(i=1; i<=t; i++){
		scanf("%d", &n);
		sum=0;
		for(k=2; k*(k+1)/2<=n; k++){
			sum=(sum+dp[n][k])%mod;
		}
		printf("%d\n", sum);
	}
	return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值