Cut the rope
http://acm.nyist.net/JudgeOnline/problem.php?pid=651
描述
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
/*
1+2+3+4+...+k=(k+1)*k/2
N = 500000 (长度)
解得k = 316
dp[n][k]表示长度为n的线段分解成k段的方案数。
有2种情况:
1.有长度为1的:dp[n-k][k-1]
2.没有长度为1的;每段的长度减1后,与dp[n-k][k]的方案数相同 所以dp[n][k] = (dp[n-k][k-1]+dp[n-k][k])%Mod
观察dp,dp[n][k]需要的是左上角和上的信息。
所以递归基础是k=2和n=2的情况。(第一行第一列)
n=2, dp[2][i] = 0
k=2, dp[i][2] = (i-1)/2 ans[i]就是对dp[i][*]求和.
*/
#include <iostream>
#include <cstring>
using namespace std; #define N 50002
#define K 316
#define Mod 1000000
int m;
int n;
int dp[N][K];
int ans[N]; void pre()
{
ans[] = ans[] = ; for (int i = ; i < K; ++i)
dp[][i] = ;
for (int i = ; i < N; ++i)
dp[i][] = (i-)/; for (int i = ; i < N; ++i)
{
for (int j = ; j < K; ++j)
{
if (i-j >= )
dp[i][j] = (dp[i-j][j-] + dp[i-j][j])%Mod;
}
} for (int i = ; i < N; ++i)
for (int j = ; j < K; ++j)
ans[i] = (ans[i]+dp[i][j])%Mod;
} int main()
{
pre(); cin >> m; while (m--)
{
cin >> n; cout << ans[n] << endl;
}
}
Cut the rope的更多相关文章
- hdu 4476 Cut the rope (2-pointer && simulation)
		
Problem - 4476 题意是,给出若干绳子,对同一根绳子只能切割一次,求出最多能获得多少长度相同的绳子. 代码中,s是最大切割长度,而当前切割长度为t/2. 代码如下: #include &l ...
 - [Algo] 87. Max Product Of Cutting Rope
		
Given a rope with positive integer-length n, how to cut the rope into m integer-length parts with le ...
 - 推荐10款超级有趣的HTML5小游戏
		
HTML5的发展速度比任何人的都想像都要更快.更加强大有效的和专业的解决方案已经被开发......甚至在游戏世界中!这里跟大家分享有10款超级趣味的HTML5游戏,希望大家能够喜欢! Kern Typ ...
 - 8个超棒的HTML5网站设计欣赏
		
我们听到了很多关于HTML5的新闻和技术动向,一个又一个的新的东西不停的出现,那么最近HTML5的技术应用又如何呢?HTML5又和CSS及其Javascript如何一起改变我们的网站设计和实现的呢? ...
 - Codeforces Round #384 (Div. 2)D-Chloe and pleasant prizes
		
D. Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input ...
 - Bungee Jumping[HDU1155]
		
Bungee JumpingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
 - coderforces #384 D Chloe and pleasant prizes(DP)
		
Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...
 - Codeforces Round #384 (Div. 2)A,B,C,D
		
A. Vladik and flights time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
 - Codeforces Round #384 (Div. 2)D - Chloe and pleasant prizes 树形dp
		
D - Chloe and pleasant prizes 链接 http://codeforces.com/contest/743/problem/D 题面 Generous sponsors of ...
 
随机推荐
- 在Oracle Enterprise Linux R5U7上安装Oracle 11gr2数据库
			
折腾了好几次,经验是: 包的安装 在安装包里,需要把开发方面的安装包都装上. 另外安装完成后,需要安装的包包括: cd /media/cdrom/Server rpm -Uvh binutils-2. ...
 - 正确看待POW与POS,总结与区分
			
POW:Proof of Work,工作证明. 比特币在Block的生成过程中使用了POW机制,一个符合要求的Block Hash由N个前导零构成,零的个数取决于网络的难度值.要得到合理的Block ...
 - iOS:二维码的扫描
			
iOS 中二维码的扫描借用#import <AVFoundation/AVFoundation.h> 实现,会用到<AVCaptureMetadataOutputObjectsDel ...
 - 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:3.安装Oracle RAC-3.6.集群管理命令
			
3.6. 集群管理命令 3.6.1. RAC的启动与关闭 oracle rac默认会开机自启动,如需维护时可使用以下命令: 关闭: crsctl stop cluster 停止本节点集群服务 crsc ...
 - 面试题:判断两个字符串是否互为回环变位(Circular Rotaion)
			
题干: 如果字符串 s 中的字符循环移动任意位置之后能够得到另一个字符串 t,那么 s 就被称为 t 的回环变位(circular rotation). 例如,ACTGACG 就是 TGACG ...
 - 算法导论-求x的n次方
			
目录 1.分治求x的n次方思路 2.c++代码实现 内容 1.分治求x的n次方思路T(n)=Θ(lgn) 为了计算乘方数a^n,传统的做法(所谓的Naive algorithm)就是循环相乘n次,算法 ...
 - solr File Upload "Unsupported ContentType: application/vnd.ms-excel  Not in: [application/xml, application/csv, application/json, text/json, text/csv, text/xml, application/javabin]",
			
今天在用solr管理界面导入文件时报错:"Unsupported ContentType: application/vnd.ms-excel Not in: [application/xm ...
 - iOS开发- 自己主动消失的弹出框
			
- (void)timerFireMethod:(NSTimer*)theTimer//弹出框 { UIAlertView *promptAlert = (UIAlertView*)[theTimer ...
 - HA分布式集群配置三  spark集群配置
			
(一)HA下配置spark 1,spark版本型号:spark-2.1.0-bin-hadoop2.7 2,解压,修改配置环境变量 tar -zxvf spark-2.1.0-bin-hadoop2. ...
 - python实现word2vec训练结果bin文件转txt文件
			
经理让我把word2vec训练后得到的bin文件转为txt文件,目前还不知道txt文件用来干什么.其实word2vec训练语料时可以选择训练处出bin文件或者txt文件,但是训练出bin文件时过程太漫 ...