Milliard Vasya's Function-Ural1353动态规划
| Time limit: 1.0 second | Memory limit: 64 MB |
|---|
Vasya is the beginning mathematician. He decided to make an important contribution to the science and to become famous all over the world. But how can he do that if the most interesting facts such as Pythagor’s theorem are already proved? Correct! He is to think out something his own, original. So he thought out the Theory of Vasya’s Functions. Vasya’s Functions (VF) are rather simple: the value of the Nth VF in the point S is an amount of integers from 1 to N that have the sum of digits S. You seem to be great programmers, so Vasya gave you a task to find the milliard VF value (i.e. the VF with N = 109) because Vasya himself won’t cope with the task. Can you solve the problem?
Input
Integer S (1 ≤ S ≤ 81).
Output
The milliard VF value in the point S.
Sample
| input | output |
|---|---|
| 1 | 10 |
Problem Author: Denis Musin
Problem Source: USU Junior Championship March’2005
计算[0,10^9]之间有多少各数的各位之和为s,Dp[i][j]表示前i位中和为j的个数,则对于第i为k是它的个数为Dp[i][j]+=Dp[i-1][j-k].
所以递推式就出来了。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int Dp[10][83];
int main()
{
memset(Dp,0,sizeof(Dp));
for(int i = 0;i<=9;i++)//初始化第一位
{
Dp[1][i]=1;
}
for(int i=2;i<=9;i++)
{
for(int j=0;j<=81;j++)
{
Dp[i][j]= Dp[i-1][j];
}
for(int j=0;j<=81;j++)
{
for(int s = 1;s<=9&&s<=j;s++)
{
Dp[i][j] +=Dp[i-1][j-s];
}
}
}
int n;
Dp[9][1]++;//因为1000000000计算不到,所以要加上
while(~scanf("%d",&n))
{
printf("%d\n",Dp[9][n]);
}
return 0;
}
Milliard Vasya's Function-Ural1353动态规划的更多相关文章
- 递推DP URAL 1353 Milliard Vasya's Function
题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...
- ural 1353. Milliard Vasya's Function(背包/递归深搜)
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning ma ...
- ural 1353. Milliard Vasya's Function(dp)
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning ma ...
- URAL 1353 Milliard Vasya's Function(DP)
题目链接 题意 : 让你找出1到10^9中和为s的数有多少个. 思路 : 自己没想出来,看的题解,学长的题解报告 题解报告 //URAL 1353 #include <iostream> ...
- ural 1353. Milliard Vasya's Function
http://acm.timus.ru/problem.aspx?space=1&num=1353 #include <cstdio> #include <cstring&g ...
- Codeforces 837E. Vasya's Function
http://codeforces.com/problemset/problem/837/E 题意: f(a, 0) = 0; f(a, b) = 1 + f(a, b - gcd(a, b)) ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- Ural 1353 Milliard Vasya's Function(DP)
题目地址:Ural 1353 定义dp[i][j].表示当前位数为i位时,各位数和为j的个数. 对于第i位数来说.总能够看成在前i-1位后面加上一个0~9.所以状态转移方程就非常easy出来了: dp ...
- Codeforces 837E Vasya's Function - 数论
Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = ...
随机推荐
- js 时间函数封装
html代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- 用TPP开启TDD的easy模式
Test-Drived Development 测试驱动开发三步曲:写一个失败的测试用例->编写生产代码通过这个测试用例(transformation)->重构(refactor).重构是 ...
- DotNetBar grid筛选 按时间筛选
PatientDiaryPanel.Columns["RECORDDATE"].FilterExpr = string.Format("date(RECORDDATE) ...
- Java 三章错题
1.每个类都使用Object作为超类.所以对象(包括数组)都实现这个类的方法. 2.在不明确给出超类的情况下,java会自动把object作为要定义的超类. 可以使用类型为Object的变量指向任意类 ...
- php页面如何增加下载软件功能
php <?php $array = parse_ini_file("sample.ini"); ?> <a id="btnDownloadFull&q ...
- mysql的三种驱动类型
http://862123204-qq-com.iteye.com/blog/1566581 1. Class.forName("com.mysql.jdbc.Driver");/ ...
- 如何做好GPS平台软硬件集成测试
集成测试是为了构建一个更大的系统或平台,这个系统的几个部分通常是由不同的团队或甚至不同的公司开发的,以前在做信息化的软件开发时,面临的集成测试通常是不同软件子系统之间的集成测试,往往被这一阶段的测试搞 ...
- CSS/HTML 改变鼠标指针形状
改变鼠标指针形状的方法有两种:第一种:用的来改变鼠标指针形状.另一种是:利用第三方控件的方法,而我自己最常用的是第一种:用css样式表来改变鼠标指针形状 我们先来看第一种:用来改变鼠标指针形状. 有些 ...
- Array.prototype.slice.call(arguments)
Array.prototype.slice.call(arguments)能够将具有length属性的对象转化为数组, 可以理解为将arguments转化成一个数组对象,让它具有slice方法 如: ...
- Asp.net MVC5 框架揭秘 S412 实例解析 – 绝妙的扩展 模式的胜利
Asp.net MVC5 框架是个 开源的,处处可扩展的框架. 蒋先生 在他的这本书里 对如何理解框架,如何扩展框架, 给出了大量的说明和实例. 先上效果图 大部分做传统BS 的同学看到这个页面,脑海 ...