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. 整理一些css在使用中的小技巧(进行中)

    1. 消除li排列display:inline-block的间隙 ul{ font-size:; } ul li{ display:inline-block; }

  2. HTML5扩展之微数据与丰富网页摘要itemscope, itemtype, itemprop

    HTML5扩展之微数据与丰富网页摘要 by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpr ...

  3. qmake 小结(Qt 5.4)

    FROMS 变量的定义必须在include之前. MOC_DIR UI_DIR RCC_DIR 的定义必须使用绝对路径.

  4. Python学习笔记——基础篇【第五周】——random & time & datetime模块

    random模块 随机数 mport random print random.random() print random.randint(1,2) print random.randrange(1,1 ...

  5. 从P1到P7——我在淘宝这7年(转)

    作者: 赵超  发布时间: 2012-02-25 14:47  阅读: 114607 次  推荐: 153   [收藏] (一) 2011-12-08 [原文链接] 今天有同事恭喜我,我才知道自己在淘 ...

  6. c#中命令copy已退出,返回值为1

    c#中命令copy已退出,返回值为1 本正经的道:董姐刚才你说的修心养性其中的'修心'我 有孕在身刚好由戴梦瑶顶替了她的位置按照的指示 ╋旆呆 湎术葶页 邾箕砜笳 烦璜卿廑 奶奶个腿儿的等下次非让你 ...

  7. re2c实例

    #include <stdio.h> #include "demo_def.h" #define T_BEGIN 0 #define T_NUMBER 1 #defin ...

  8. java-jvisualvm远程监控tomcat

    一.修改要访问的远程主机(Linux)相关文件,本文档只介绍了java-jvisualvm的JMX方式: 1.打开$CATALINA_HOME/bin/startup.sh, 找到倒数第二行(也就是e ...

  9. scala优点以及eclipse上安装scala插件

    可拓展 (面向对象,函数式编程) 静态类型化 (可检验,安全重构) 兼容JAVA (类库调用,互操作) 支持并发控制 (强计算能力,自定义其他控制结构) 语法简洁 (代码行短,类型推断,抽象控制) 插 ...

  10. 开机自动挂载 VHD 的方法

    一.批处理 除了将 VHD 文件用人工方式在[磁盘管理]里[附加]来挂载以外,也能用[脚本]来实现自动挂载. 打开[启动],将写好的 mount.bat 放入即可: Mount.bat 文件的内容为: ...