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. CodeForces 670B Game of Robots

    简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...

  2. "The Application was unable to start correctly (0xc000007b). Click OK to close the application"

    我有时将MFC编译成64位并运行,就会报这个错误. 后来查找原因,就在于系统中使用了错误的dll.比如这个程序要使用64位的dll,而你拷贝进去的是同名的32位dll.解决方法就是放置正确的dll. ...

  3. [SQL基础教程] 2-3 逻辑运算符

    [SQL基础教程] 2-3 逻辑运算符 NOT AND OR 优先级 ( )改变优先级 AND 优先级高于 OR NULL 引入三值逻辑

  4. 一篇顺手的Ubuntu+caffe配置笔记

    主要参考: https://github.com/lbzhang/dl-setup http://ouxinyu.github.io/Blogs/20151108001.html http://www ...

  5. OGC 的WCS WFS 及WMS 服务

    OGC--Open Geospatial Consortium--开放地理信息联盟,是一个非盈利的志愿的国际标准化组织,引领着空间地理信息标准及定位基本服务的发展目前在空间数据互操作领域,基于公共接口 ...

  6. 生成元(Digit Generator,ACM/ICPC Seoul 2005,UVa 1583)

    #include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int t, n, a, ...

  7. HDU 5839 Special Tetrahedron

    HDU 5839 Special Tetrahedron 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5839 Description Given n ...

  8. Debian7安装php5.5/5.6

    ### 1 添加源 echo "deb http://packages.dotdeb.org wheezy-php56 all" >> /etc/apt/sources ...

  9. 找出Java数组中不同的值

    public void deltp(PrintWriter out) { try{ PageData pd = new PageData(); pd = this.getPageData(); Str ...

  10. angular指令

    转自:http://www.cnblogs.com/rohelm/p/4051437.html 对于指令,可以把它简单的理解成在特定DOM元素上运行的函数,指令可以扩展这个元素的功能. 首先来看个完整 ...