UVA 10943 How do you add? DP
Larry is very bad at math — he usually uses a calculator, which
worked well throughout college. Unforunately, he is now struck in
a deserted island with his good buddy Ryan after a snowboarding
accident.
They’re now trying to spend some time figuring out some good
problems, and Ryan will eat Larry if he cannot answer, so his fate
is up to you!
It’s a very simple problem — given a number N, how many ways
can K numbers less than N add up to N?
For example, for N = 20 and K = 2, there are 21 ways:
0+20
1+19
2+18
3+17
4+16
5+15
...
18+2
19+1
20+0
Input
Each line will contain a pair of numbers N and K. N and K will both be an integer from 1 to 100,
inclusive. The input will terminate on 2 0’s.
Output
Since Larry is only interested in the last few digits of the answer, for each pair of numbers N and K,
print a single number mod 1,000,000 on a single line.
Sample Input
20 2
20 2
0 0
Sample Output
21
21
题意: 给你N,k 计算k个数相加等于N的方案数, 1,100 输出100
题解:设定dp[n][k] dp[i][j] = ∑ dp[k][j - 1](0 ≤ k ≤ i)。
//meek///#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int inf = ;
const int mod= ; int dp[N][N]; //n//k
int n,k;
int main() {
for(int i=;i<=;i++) dp[][i] += ;
//for(int i=0;i<=100;i++) dp[i][1] += 1;
for(int i=;i<=;i++) {
for(int j=;j<=;j++) {
for(int h=;h<=i;h++)
dp[i][j] += dp[h][j-],dp[i][j] %= ;
}
}
while(~scanf("%d%d",&n,&k)) {
if(n==&&k==) break;
printf("%d\n",dp[n][k]);
}
return ;
}
daima
UVA 10943 How do you add? DP的更多相关文章
- UVA 10943 - How do you add? 递推
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 10943 How do you add?
设函数 f(k)(n); 则: f(1)(n)=1; f(2)(n)=f(1)(0)+f(1)(1)+f(1)(2)+...+f(1)(n); f(3)(n)=f(2)(0)+f(2)(1)+f(2) ...
- UVa 10943 How do you add?【递推】
题意:给出n,k,问恰好有k个不超过n的数的和为n的方案数有多少 可以隔板法来做 现在有n个小球放到k个盒子里面,盒子可以为空 那么就是n-k+1个缝隙,放上k-1个隔板(k-1个隔板就分成了k份) ...
- UVA 10163 Storage Keepers(两次DP)
UVA 10163 Storage Keepers(两次DP) http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Ite ...
- uva 11584 Partitioning by Palindromes 线性dp
// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串 ...
- UVA - 825Walking on the Safe Side(dp)
id=19217">称号: UVA - 825Walking on the Safe Side(dp) 题目大意:给出一个n * m的矩阵.起点是1 * 1,终点是n * m.这个矩阵 ...
- UVa 10943 (数学 递推) How do you add?
将K个不超过N的非负整数加起来,使它们的和为N,一共有多少种方法. 设d(i, j)表示j个不超过i的非负整数之和为i的方法数. d(i, j) = sum{ d(k, j-1) | 0 ≤ k ≤ ...
- How do you add? UVA - 10943(组合数的隔板法!!)
题意: 把K个不超过N的非负整数加起来,使它们的和为N,有多少种方法? 隔板法...不会的可以买一本高中数学知识清单...给高中班主任打个广告.... 隔板法分两种...一种是不存在空集 = C(n- ...
- UVa 1637 - Double Patience(概率DP)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- Linux如何开机自动运行自己的脚本
博客分类: LINUX 脚本LinuxCentOSWindowsBash 记录这个事情是上次完成之后,今天要新加一个文件夹,一时之间忘记以前怎么做了,因为有几种方法,起码我知道三种方法,这里 ...
- C# SQL增删查改
DBHelper: /// <summary> /// 执行查询 /// </summary> /// <param name="sql">有效 ...
- 动态链接库知识点总结之三(如何以显示的方式加载DLL)
总结一下如何显示加载方式加载DLL, 首先,我们新建一个win32项目,选择dll,空项目,再添加一个源文件,一个模块定义文件(.def),具体如下图.(详细方法已经在前两篇文章中讲述,如有不懂,打开 ...
- [磁盘管理与分区]——关于分区、磁盘分区表、MBR
磁盘连接与设备文件名的关系 1. 如下图所示:
- 软件工程随堂小作业——随机四则运算(C++)
一.设计思路: 1.程序的主体部分是循环输出,次数即题目数目由用户输入: 2.三个整型变量+rand函数来实现随机数四则运算,一个变量代表加减乘除,另外两个用作运算数: 3.用户体验:题目分三列,排列 ...
- Android 上传图片到 Asp.Net 服务器的问题
最近在做一个手机app联合系统管理做的应用程序,管理程序管理数据的发布和增删改查,手机app负责显示和操作业务逻辑这么一个功能. 刚开始路走的都很顺,但是走到通过Android客户端上传图片到Asp. ...
- Node.js 学习(五)Node.js 事件循环
Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调用,并处理并发. Node.j ...
- gmail邮箱怎么批量删除邮件
转载:http://jingyan.baidu.com/article/9f7e7ec056cbcd6f2815543c.html 首先打开gmail邮箱,随便打开一封邮件,找到发件人邮件地址,复制, ...
- Netsharp快速入门(之2) 基础档案(之A 创建插件和资源)
作者:秋时 杨昶 时间:2014-02-15 转载须说明出处 第三章 基础档案开发 本文不再对此需求进行分析设计,其实分析设计的结果在下文会体现在平台的使用过程中,这个销售系统分成两个模 ...
- Drools规则加载变量冲突问题分析
问题现象说明 在个别环境下加载规则时出现:rule/trade/hg/Rule_FY_*.java (53:3948) : Duplicate local variable paraMap,出现此问题 ...