hdu 5185(动态规划)
Equation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 500 Accepted Submission(s): 168
x1+x2+x3+⋯+xn=n, and here
For a certain n, Gorwin wants to know how many combinations of xi satisfies above condition.
For the answer may be very large, you are expected output the result after it modular m.
In the next T lines, every line contain two integer n,m.
[Technical Specification]
1≤T<20
1≤n≤50000
1≤m≤1000000000
each case output should occupies one line, the output format is Case
#id: ans, here id is the data number starting from 1, ans is the result
you are expected to output.
See the samples for more details.
3 100
5 100
Case #2: 3
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <algorithm>
#include <math.h>
using namespace std;
int dp[][];
int main()
{
int tcase,t=;
scanf("%d",&tcase);
while(tcase--){
int n,m;
scanf("%d%d",&n,&m);
int k = ;
while(k*(k+)<=*n) k++;
memset(dp,,sizeof(dp));
dp[][] = ;
for(int i=;i<=k;i++){
for(int j=i;j<=n;j++){
dp[i][j] = (dp[i][j-i]+dp[i-][j-i])%m;
}
}
int ans = ;
for(int i=;i<=k;i++){
ans = (ans+dp[i][n])%m;
}
printf("Case #%d: %d\n",t++,ans);
}
return ;
}
hdu 5185(动态规划)的更多相关文章
- hdu 5185 动态规划 分析降低复杂度
这题说的是 x[1]+x[2]+x[3]+…+x[n]=n, 这里 0 <= x[i] <= n && 1 <= i <= n x[i] <= x[i+1 ...
- hdu 1087 动态规划之最长上升子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1087 Online Judge Online Exercise Online Teaching Online C ...
- HDU 1003 动态规划
http://acm.hdu.edu.cn/showproblem.php?pid=1003 这几天开始刷动归题目,先来一道签到题 然而做的并不轻松, 没有注意到边界问题, WA了几发才发现 #inc ...
- hdu 4055 && hdu 4489 动态规划
hdu 4055: 一开始我想的递推方向想得很复杂,看了别人的博客后才醍醐灌顶: 参照他的思路和代码: #include<cstdio> #include<cstring> # ...
- hdu 4745 动态规划
思路:特水的一个最长回文子序列动态规划.比赛时硬卡第一题,49WA后终于AC,可惜没时间做这题,结果成绩也就可想而知了.兔子跳一样权值的石头,并且一个正跳,一个反跳,这不就是个回文子序列吗?????! ...
- hdu 4711 动态规划
思路:其实这题是个挺水的动态规划,一开始就能AC,可是不知道错哪了,瞎改瞎交,WA了数十次.AC之后怎么改都是AC,也不知道改了什么地方,郁闷死了~~~难道开始时的测试数据有问题??? dp[i][j ...
- HDU 6076 (动态规划)
HDU 6076 Security Check Problem : 有两个长度为n的队列过安检,每个人有一个特征值.如果两个队列中的第一个人的特征值之差小于等于k,那么一次只能检查其中一个人,否则一次 ...
- HDU 1171 Big Event in HDU (动态规划、01背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 4719 动态规划
思路:dp[i]表示到第i个点为结尾能获得的最大值,那么dp[i]=h[i]*h[i]+dp[i-x]-h[i-x];(i-l<=x<=i);那么我们可以转换下,以dp[i]-h[i]为新 ...
随机推荐
- gradle在build之后执行任务
在打包后一般会有copy jar文件的需求. 先在build.gradle文件中定义你的task: task myCopy{ println "some copy code..." ...
- 《学习OpenCV》课后习题解答9
题目:(P126) 创建一个程序,使其读入并显示一幅图像.当用户鼠标点击图像时,获取图像对应像素的颜色值(BGR),并在图像上点击鼠标处用文本将颜色值显示出来. 解答: 本题关键是会用cvGet2D获 ...
- 【SSH】——使用ModelDriven的利与弊
在以往的web开发中,如果要在表单显示什么内容,我们就需要在Action中提前定义好表单显示的所有属性,以及一系列的get和set方法.如果实体类的属性非常多,那么Action中也要定义相同的属性.在 ...
- background 背景图铺满界面
background <body background="/image/1.png" style=" background-repeat:no-repeat ; b ...
- hdu 1575 Tr A (二分矩阵)
Tr A Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 从CUBIC/BBR的TCP ACK失速说起
上周有同事问,延迟ACK到底对应用层会产生什么后果,我也不知道该如何作答,于是丢了一个链接: TCP之Delay ACK在Linux和Windows上实现的异同-Linux的自适应ACK: 是的,这是 ...
- Linux(CentOS)用split命令分割文件
在 Linux 里,稍加不注意有可能会产生很大体积的日志文件,哪怕几百M,拖下来分析也很浪费时间,这个时候,如果可以把文件切割成 N 个小文件,拿最后一个文件就可以看到最近的日志了.有一些手段,比如用 ...
- Kafka自我学习3-Scalable
1.After created the zookeeper cluster, we found all broker cluster topic can be find in zoo1, zoo2, ...
- dbcp基本配置和重连配置
转载自:http://agapple.iteye.com/blog/772507 最近在看一些dbcp的相关内容,顺便做一下记录,免得自己给忘记了. 1. 引入dbcp (选择1.4) Java代码 ...
- windows10-seaslog安装笔记
1.seasLog在windows下的安装 首先,要下载seasLog的dll文件,下载地址:http://pecl.php.net/package/SeasLog 选择对应你的系统和php版本的d ...