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 ...
随机推荐
- linux & windows 共享 smbd 部署
smbd : yum install samba samba-client samba-swat mount.cifs : yum -y install cifs-utils ##挂载nas 文 ...
- 一天干掉一只Monkey计划(一)——基本光照模型及RT后处理 【转】
http://www.cnblogs.com/Zephyroal/archive/2011/10/10/2206530.html 一天干掉一只Monkey计划(一)——基本光照模型及RT后处理 1, ...
- Java源码阅读LinkedHashMap
1类签名与注释 public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V> 哈 ...
- 持续集成之代码质量管理-Sonar
原文:http://blog.csdn.net/abcdocker/article/details/53840582 Sonar介绍 Sonar 是一个用于代码质量管理的开放平台.通过插件机制,Son ...
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-人机界面HMI自锁按钮和自复位按钮如何理解(Toggle variable Tap variable)
我分别创建两个按钮,自锁和自复位,绑定到主程序的两个布尔值上去 自锁按钮是指点击一下为TRUE,再点击一下为FALSE,自复位按钮是指按下的时候为TRUE,松开的时候为FALSE(也可以勾选Tap ...
- 使用Python发送电子邮件
使用python发送邮件并不难,这里使用的是SMTP协议. Python标准库中内置了smtplib,使用它发送邮件只需提供邮件内容与发送者的凭证即可. 代码如下: # coding:utf-8 im ...
- CentOS 5 全功能WWW服务器搭建全教程 V3.0
http://hx100.blog.51cto.com/44326/339949/ 一.基本系统安装1.下载CentOS 5我是下载的DVD版本,大家也可以下载服务器CD安装版本,其实都差不多.大家可 ...
- Loadrunner11之VuGen常用函数lr_user_data_point(一)
Loadrunner11之VuGen常用函数lr_user_data_point(一) 上一篇 / 下一篇 2011-11-15 00:15:33 / 精华(1) / 置顶(1) / 个人分类:性能 ...
- MATLABR 2016 b 安装教程
1.下载相应的 MATLABR 2016 b 版本如下: 主要是下面三个文件,其中, Matlab 2016b Win64 Crack.rar 是破解文件.另两个为安装包.(本软件在win8/10上不 ...
- vs mvc 视图中找不到 viewdata viewbag的解决方案
1.查看views下的web.config文件是否存在 2.检查config中system.web.mvc ,version中版本号与自己的vs内置mvc版本一致 迁移项目可能有此问题