hdoj 5185 Equation (线性dp 完全背包)
来源:互联网 发布:下载播音录音软件 编辑:程序博客网 时间:2024/06/05 00:33
题目大意:问按照题目所给的公式,有多少种不同的方法得到n,方法数对m取余
有条件x[i+1]-x[i]>=1;
mx * (mx + 1) / 2 == n
化简可以得到mx = (sqrt(8n + 1) - 1) / 2
递推方程是dp[i][j]=dp[i][j-i]+dp[i-1][j-i];
前i个数字合成j的种类数等于合成j-i时放了i和没放i两种情况的和,dp[0][0] = 1;
#include<stdio.h>#include<algorithm>#include<math.h>using namespace std;int dp[333][50001];int main(){ int T,k=1; scanf("%d",&T); while(T--) { int n,m; scanf("%d%d",&n,&m); int mx=(int)((sqrt(8*n+1)-1)/2); dp[0][0]=1; for(int j=1;j<=n;j++) { for(int i=1;i<=min(j,mx);i++) dp[i][j]=(dp[i-1][j-i]+dp[i][j-i])%m; } int ans=0; printf("Case #%d: ",k++); for(int i=1;i<=mx;i++) ans=(ans+dp[i][n])%m; printf("%d\n",ans); } return 0;}
0 0
- hdoj 5185 Equation (线性dp 完全背包)
- HDU 5185 Equation (线性dp 完全背包)
- 【DP】 HDOJ 5185 Equation
- hdu 5185 Equation (完全背包变形)
- HDU 5185 Equation 完全背包变形.
- HDU 3127 WHUgirls (线性dp 完全背包)
- HDU 1069 Monkey and Banana (线性dp 完全背包)
- HDOJ 1248 寒冰王座【DP】【完全背包】
- HDOJ(HDU).1114 Piggy-Bank (DP 完全背包)
- HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包)
- HDOJ 4249 A Famous Equation DP
- HDU 5185 Equation (DP)
- hdu 5185 dp(完全背包)+优化
- HDU1248 完全背包 DP
- HDU2189(完全背包+DP)
- nyoj311 完全背包 【dp】
- uva10313(DP完全背包)
- UVA674 完全背包DP
- 做智能硬件产品经理与做互联网的有什么不同?
- PAT 1001. A+B Format (20)
- 初学Android,创建,启动,停止Service(五十八)
- HTTP详解(1)-工作原理
- 中文编码转换---6种编码30个方向的转换
- hdoj 5185 Equation (线性dp 完全背包)
- 查找字符串(containsString和rangeOfString的区别)
- I/O流
- [转]自动化运维工具Ansible
- 如果孔子当了码工
- HTTP详解(2)-请求、响应、缓存
- jQuery实用基础超详细介绍
- HTTP详解(3)-http1.0 和http1.1 区别
- linux模块的卸载