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& ...
随机推荐
- hdu 1434 幸福列车
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1434 幸福列车 Description 一批幸福的列车即将从杭州驶向幸福的终点站——温州,身为总列车长 ...
- golang的nil
golang中什么样的类型可以赋值nil? 类型文档中有注定"uninitialized value is nil"的类型都可以赋值nil. golang的基本类型不能赋值nil: ...
- IOS中的UINavigationController(导航控制器)
UINavigationController UINavigationControlle:导航控制器,是iOS中最常用的多视图控制器之一,它用来管理多个试图控制器 导航控制器可以认为是管理控制器的控制 ...
- MVC4.0 实现单一Action返回多种结果
在开发过程中,我们往往会遇到这种情况.例如:展示学生的详细信息页面,加载学生的详细信息局部视图,异步请求学生的详细信息Json数据等等. 一般情况下,我们会写三个不同的action来支撑前台数据的调用 ...
- JSON数组操作
在jquery中处理JSON数组的情况中遍历用到的比较多,但是用添加移除这些好像不是太多. 今天试过json[i].remove(),json.remove(i)之后都不行,看网页的DOM对象中好像J ...
- java rest框架jersey数组单记录问题解决
JAVA数据接口采用jersey技术,可以返回xml,json等格式,可以根据客户端请求accept,如:Application/json,Application/xml 来得到不同的接口数据,非常好 ...
- Liferay IDE3.1 M1的一些新功能
定于11月发布的Liferay IDE提供了一些让人期许的功能 1. code upgrade tools 这个工具将会帮助你把liferay 6.2的项目升级为7.0的项目.下面列举其主要功能 1. ...
- 【转】eclipse技巧2
谈谈eclipse使用技巧二 上节说道了怎么使用eclipse使您事半功倍.这节告诉您怎么用eclipse练成火眼金睛. ①借你一双火眼金睛让类的层次结构一目了然让你阅读代码如虎添翼 一个好的类的层次 ...
- AxMicrosoft.Office.Interop.Owc11.AxSpreadsheet控件在C#中的引用
这几天要是用AxMicrosoft.Office.Interop.Owc11.AxSpreadsheet控件做查询,发现一系列问题,一点点记录下来吧,以备后查: 第一.相关属性:http://www. ...
- 2、onclickListener冲突
事情是这样的. 我在activity中同时使用普通按钮和对话框按钮,并都设置点击时候的回调函数,由于都要用到onclickListener,但是两者却不是一个文件,无法同时import,这就是本文出现 ...