题目:http://poj.org/problem?id=3181

思路:将整数N划分为一系列正整数之和,最大不超过K。称为整数N的K划分。

递归:直接看代码:

动态规划:dp[i][j]:=将整数i做j划分的方法数。

dp[i][j]=dp[i][i]; if(j>i)

dp[i][j]=dp[i-j][j]+dp[i][j-1];//分j出现不出现两种情况

dp[i][j]=dp[i][j-1]+1;if(i==j)//单独的一个j和另外一种不包含j

#include <iostream>
#include <cstring>
using namespace std;
unsigned long f(int n, int max) // 将整数n划分成一系列整数序列之和,序列最大数为max
{
if (n == 1 || max == 1)
return 1;
else if (n < max)
return f(n, n);
else if (n == max)
return 1 + f(n, max-1);
else
return f(n,max-1) + f(n-max, max);
}
long long dp[1100][110];
int main()
{
//cout<<f(5,3)<<endl; // 将5划分成1,2,3组成的序列之和的方法数
int n,k;
while(cin>>n>>k)
{
memset(dp,0,sizeof(dp)); for(int i=0;i<=k;i++) dp[0][i]=1; for(int i=1;i<=k;i++)
{
for(int j=1;j<=n;j++){
if(i>j) dp[j][i]=dp[j][j];
else if(i==j) dp[j][i]=1+dp[j][i-1]; //其实可以归纳到下面一种情况
else dp[j][i]=dp[j-i][i]+dp[j][i-1]; }
}
cout<<dp[n][k]<<endl;
}
}

poj 3181 Dollar Dayz (整数划分问题---递归+DP)的更多相关文章

  1. POJ 3181 Dollar Dayz(全然背包+简单高精度加法)

    POJ 3181 Dollar Dayz(全然背包+简单高精度加法) id=3181">http://poj.org/problem?id=3181 题意: 给你K种硬币,每种硬币各自 ...

  2. POJ 3181 Dollar Dayz && Uva 147 Dollars(完全背包)

    首先是 Uva 147:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_p ...

  3. poj 3181 Dollar Dayz(完全背包)

    Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5419   Accepted: 2054 Descr ...

  4. POJ 3181 Dollar Dayz DP

    f[i][j]=f[i-j][j]+f[i][j-1],结果很大需要高精度. //#pragma comment(linker, "/STACK:1024000000,1024000000& ...

  5. POJ 3181 Dollar Dayz 简单DP

    这DP虽然简单 但是思考一下还是挺好的 题意是 1,2,3,4....k 用加法凑成N 每个数可取不限个数 令dp[i][j] 表示前i种数凑成j的方案数 然后dp[i][j] = dp[i - 1] ...

  6. POJ 3181 Dollar Dayz(高精度 动态规划)

    题目链接:http://poj.org/problem?id=3181 题目大意:用1,2...K元的硬币,凑成N元的方案数. Sample Input 5 3 Sample Output 5 分析: ...

  7. POJ 3181 Dollar Dayz 【完全背包】

    题意: 给出两个数,n,m,问m以内的整数有多少种组成n的方法完全背包+大数划分 思路: dp[i][j] := 用i种价格配出金额j的方案数. 那么dp[i][0] = 1,使用任何价格配出金额0的 ...

  8. POJ 3181 Dollar Dayz (完全背包,大数据运算)

    题意:给出两个数,n,m,问1~m中的数组成n,有多少种方法? 这题其实就相当于 UVA 674 Coin Change,求解一样 只不过数据很大,需要用到高精度运算... 后来还看了网上别人的解法, ...

  9. poj 3181 Dollar Dayz

    题意:给定一个数p,要求用K种币值分别为1,2,3...K的硬币组成p,问方案数,1,2,2和2,2,1算一种方案即与顺序无关,n <= 1000,k <= 100// 用完全背包做了 这 ...

随机推荐

  1. spring源码分析构建

    命令如下: ant ant install-maven ant jar package E:\download\spring-framework-3.1.3.RELEASE\build-spring- ...

  2. sql数据库之间数据的转录

    private void Form1_Load(object sender, EventArgs e) { BindDataBase(combDataBaseNew, , ""); ...

  3. (转)SVN详解

    原文地址:http://www.weixingon.com/s/visualsvn+%E4%B8%AD%E6%96%87 1.几种代理管理工具的适用场景 A.如果你的项目是5-6人的小团队,那么使用V ...

  4. js获取当前日期时间同时显示星期

    JavaScript获取当前日期时间同时显示星期几,具体代码如下: <html> <head> <meta http-equiv="Content-Type&q ...

  5. Nagios监控memcached

    下载地址: http://search.cpan.org/CPAN/authors/id/Z/ZI/ZIGOROU/Nagios-Plugins-Memcached-0.02.tar.gz http: ...

  6. Property type 'id<tabBarDelegate>' is incompatible with type 'id<UITabBarDelegate> _Nullable' inherited from 'UITabBar'

    iOS报错:Property type 'id' is incompatible with type 'id _Nullable' inherited from 'UITabBar' 如图: 可能原因 ...

  7. 微信js-sdk,选择图片,上传,下载到本地,php服务端

    //前端js代码<script> //客户端6.0.2 wx.config({ //debug:true, appId: "{pigcms:$signPackage.appId} ...

  8. securecrt简介

    SecureCRT是最常用的终端仿真程序,简单的说就是Windows下登录UNIX或Liunx服务器主机的软件,本文主要介绍SecureCRT的使用方法和技巧 VanDyke CRT 和 VanDyk ...

  9. 转:sprintf与snprintf

    sprintf与snprintf   int sprintf( char *buffer, const char *format [, argument] ... ); 除了前两个参数类型固定外,后面 ...

  10. SQL Server 2012数据库还原所遇到的问题

    在SQL Server2005及以下版本做数据库备份还原时,需要首先建立数据库,然后才能进行数据库还原操作:而在SQL Server2005以上版本做数据库还原时,不需要建立数据库,可以直接进行数据库 ...