1353. Milliard Vasya's Function

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

题意:求1到109中各位数字之和为s的数有多少个;

思路1:背包思路;

 #include<iostream>
#include<cstdio> using namespace std; int dp[][]={}; int main()
{
// freopen("1.txt","r",stdin);
int s;
cin>>s;
int i,j,k;
dp[][]=;
dp[][]=;
for(i=;i<;i++)
{
for(j=;j<=(i*)&&j<=s;j++)
{
dp[i%][j]=dp[-i%][j];
for(k=;k<&&k<=j;k++)
dp[i%][j]+=dp[-i%][j-k];
}
}
dp[][]++;
cout<<dp[][s]<<endl;
return ;
}

思路2:递归的深搜;

 #include<iostream>
#include<cstdio> using namespace std; int ks(int s,int k)
{
if(k==)
{
if(s>)
return ;
return ;
}
if(s==)return ;
int sum=;
int i;
for(i=;i<&&i<=s;i++)
{
sum+=ks(s-i,k-);
}
return sum;
} int main()
{
// freopen("1.txt","r",stdin);
int s;
cin>>s;
if(s==)
{
cout<<ks(s,)<<endl;
return ;
}
cout<<ks(s,)<<endl;
return ;
}

ural 1353. Milliard Vasya's Function(背包/递归深搜)的更多相关文章

  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(dp)

    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)

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

  4. ural 1353. Milliard Vasya's Function

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

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

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

  6. 剑指 Offer 12. 矩阵中的路径 + 递归 + 深搜 + 字符串问题

    剑指 Offer 12. 矩阵中的路径 题目链接 题目类似于迷宫的搜索. 需要注意的是,需要首先判断起始搜索的位置,可能有多个起点,都需要一一尝试. 每轮迭代的时候记得将是否遍历标记数组还原为未遍历的 ...

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

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

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

  9. Network Saboteur (深搜递归思想的特殊使用)

    个人心得:对于深搜的使用还是不到位,对于递归的含义还是不太清楚!本来想着用深搜构成一个排列,然后从一到n分割成俩个数组,然后后面发现根本实现不了,思路太混乱.后来借鉴了网上的思想,发现用数组来标志,当 ...

随机推荐

  1. XTU 1245 Hamiltonian Path

    $2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$C$题 简单题. 注意题目中给出的数据范围:$1 \le ai < bi \le n$,说明这是一个有向无环图,并且哈密顿路一定是$1 \ ...

  2. linux统计单词数

    sort +awk+uniq 统计文件中出现次数最多的前10个单词 实例 cat logt.log|sort -s -t '-' -k1n |awk '{print $1;}'|uniq -c|sor ...

  3. netty初探(2)

    上一篇 netty(1) 一.TCP/IP 流式传输 在上文演示了2进制流式传输引起的TCP拆包问题,这里继续演示文本型的传输问题,文本型的可以有以下几种策略 1.1 以特殊字符表示结尾 HTTP协议 ...

  4. myeclipse连接数据库oracle(添加jdbc.properties)

    第一步:在src下面建一个包com.xsl.conf 第二步:在建好的包下面新建一个jdbc.properties 第三步:在jdbc.properties里写入内容如下: driver = orac ...

  5. Linux GIT服务器配置

    Linux下安装git插件 1. 下载git网址:     https://github.com/git/git/releases 2. 放入usr/src/下 3. tar -zxvf git-** ...

  6. ng-Directive

    伪代码: var myModule = angular.module(...); myModule.directive('namespaceDirectiveName', function facto ...

  7. nodejs学习随笔

    <一> 简述nodejs (社区:www.npmjs.com)可查找一些第三方模块. nodejs是可以让js运行在浏览器之外的服务器端的平台,实现了文件系统.模块.包.操作系统API.网 ...

  8. Python 函数之路

    ---恢复内容开始--- python函数的定义 def add(): a = 1 b = 2 c == a + b print(c) 函数就是把一段实现某一个功能的代放进一个封装的方法名里,这个方法 ...

  9. sublime text 安装 SFTP

    1  先安装Package Control import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f' + '1e ...

  10. LINQ To SQL 处理 DateTime?

    LINQ To SQL 处理 DateTime? 类型 例子: 搜索栏含有最后扫描时间的日期(DateTime?)与多个其他条件(String) 现在需要写一个查询 : 查询符合最后扫描的日期的查询 ...