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动态规划的更多相关文章

  1. 递推DP URAL 1353 Milliard Vasya's Function

    题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...

  2. 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 ...

  3. 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 ...

  4. URAL 1353 Milliard Vasya's Function(DP)

    题目链接 题意 : 让你找出1到10^9中和为s的数有多少个. 思路 : 自己没想出来,看的题解,学长的题解报告 题解报告 //URAL 1353 #include <iostream> ...

  5. ural 1353. Milliard Vasya's Function

    http://acm.timus.ru/problem.aspx?space=1&num=1353 #include <cstdio> #include <cstring&g ...

  6. 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)) ...

  7. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

  8. Ural 1353 Milliard Vasya&#39;s Function(DP)

    题目地址:Ural 1353 定义dp[i][j].表示当前位数为i位时,各位数和为j的个数. 对于第i位数来说.总能够看成在前i-1位后面加上一个0~9.所以状态转移方程就非常easy出来了: dp ...

  9. 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) = ...

随机推荐

  1. gmc银联接口开发demo

    1.接口文档 1.1 无gmc界面接口 (dll/ocx) dll调用(posinf.dll)函数名为:int bankall (char * request,char *response),其中第一 ...

  2. jquery toggle方法

    $("#myDiv").toggle(function () { alert(1); }, function () { alert(2); }); 某种需求下可以替代click事件 ...

  3. Quartz2D 编程指南(四)位图与图像遮罩、CoreGraphics 绘制 Layer

    概览 图形上下文 路径 颜色与颜色空间 变换 图案 阴影 渐变 透明层 Quartz 2D 中的数据管理 位图与图像遮罩 CoreGraphics 绘制 Layer 位图与图像遮罩 简介 位图与图像遮 ...

  4. :active 为什么在ios上失效

    :active是针对鼠标,而手机上是没有鼠标,而是touchstart,所以早成了ios上不兼容 解决方法是: window.onload = function(){ document.body.ad ...

  5. ssh 配合 tar 实现远程推送

    tar命令和ssh配合使用 如何在空间不是很富裕的情况,把文件从一个分区tar到另外一个分区,其实还有很多办法的,使用管道命令就可以实现 如: #tar -cvf home |(cd /datavg3 ...

  6. C# 与数据库中字段类型 Int16(short), Int32(int), Int64(long)的取值范围、区别 。string长度

    一开始看到Int16, Int32, Int64这三种类型就觉得有点怪, 为什么要整个数字结尾的, 挺怪的. 昨天互相想到, ms这么干就是想让大家一眼就知道这个数据类型占多大空间吧. Int8, 等 ...

  7. 简化C语言文法

    程序 → 外部声明|程序 外部声明 外部声明 → 定义函数|定义 函数定义 → 类型标识符 声明部分语句 类型标识符 → 空类型|字符型|整型|浮点型 声明部分语句 → 指针 直接声明|直接声明 指针 ...

  8. [原创]java WEB学习笔记103:Spring学习---Spring Bean配置:基于注解的方式(基于注解配置bean,基于注解来装配bean的属性)

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  9. kindEditor完整认识 PHP上调用并上传图片说明/////////////////////////////z

      最近又重新捣鼓了下kindeditor,之前写的一篇文章http://hi.baidu.com/yanghbmail/blog/item/c681be015755160b1d9583e7.html ...

  10. 2.6 C#的数据转换

    C#有多种数据类型,每种数据类型只能存储这种类型的变量,但又的时候我们需要各种类型之间的转换.比如在计算2+3.5的时候,这个时候有两种情况: 自动类型转换:2种不同类型的数据运算,低精度类型的数值会 ...