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 ...
随机推荐
- 从C转到JAVA学习路之基本知识对比(转)
转自:http://blog.csdn.net/andywxf01/article/details/53502615 我一直在用C开发,想转到Java时最容易想到的事就是把C里写的代码和功能用JAVA ...
- Eclipse+Maven远程部署项目到Tomcat中
使用maven的自动部署功能可以很方便的将maven工程自动打包并且部署到远程tomcat服务器,省去一些繁琐的操作,节省大量时间. 我使用的tomcat版本是8.5,tomcat7和tomcat8都 ...
- MAC下MySQL忘记初始密码
MAC下MySQL忘记初始密码的解决方法分享给大家,供大家参考,具体内容如下 从官网安装好MySQL的dmg后. 1 设置mysql命令 从终端输入 ? 1 mysql --version 若显示版本 ...
- OpenERP7.0 忘记admin管理员密码解决办法
操作环境:linux Ubuntu12.10 OpenERP7.0 以下操作,请注意大小写 切换用户 root@ubuntu:~# su - postgres 查看数据库 postgres@ubun ...
- js中数组的splice()方法
在数组中splice方法有增.删.该的多功能用处. var list = []; list.push(1); list.push(2); list.push(3); console.log(list) ...
- Apache Nifi在Windows环境下搭建伪群集及证书登录
代码地址如下:http://www.demodashi.com/demo/11986.html 前些时间做了关于Apache Nifi分布式集群的搭建分享,但很多时候要搭建分布式集群机器资源是个问题, ...
- 转:VLC搭建RTSP直播流,图文介绍
将一个视频转成rtsp流,通过vlc播放器,搭建一个rtsp服务器,让rtsp客户端去访问这个视频的rtsp流 1 需要有vlc播放器,我的版本如下 2 媒体 --> 流 3 添加视频文件 ...
- emcas自己所熟悉的快捷键
刚开始用emacs,看完Tutorial了后又用emcas做了一些笔记. 现将自己脑海中觉得比较重要的快捷键一一列出,该列表将持续更新: C = Ctrl M = Alt 查找或打开(新)文件 C- ...
- Atitit.木马病毒 webftp 的原理跟个设计
Atitit.木马病毒 webftp 的原理跟个设计 ftp木马的效果 文件传播 文件列表 文件内容查看 作者:: ★(attilax)>>> 绰号:老哇的爪子 ( 全名::Att ...
- Atitit.跨语言数据库db api兼容性 jdbc odbc ado oledb 增强方案
Atitit.跨语言数据库db api兼容性 jdbc odbc ado oledb 增强方案 1. 跨语言db api兼容性..1 2. 目前访问数据库的接口很多.比较常用的jdbc odbc 以 ...