ural 1353. Milliard Vasya's Function(背包/递归深搜)
1353. Milliard Vasya's Function
Input
Output
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(背包/递归深搜)的更多相关文章
- 递推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(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 ...
- Ural 1353 Milliard Vasya's Function(DP)
题目地址:Ural 1353 定义dp[i][j].表示当前位数为i位时,各位数和为j的个数. 对于第i位数来说.总能够看成在前i-1位后面加上一个0~9.所以状态转移方程就非常easy出来了: dp ...
- 剑指 Offer 12. 矩阵中的路径 + 递归 + 深搜 + 字符串问题
剑指 Offer 12. 矩阵中的路径 题目链接 题目类似于迷宫的搜索. 需要注意的是,需要首先判断起始搜索的位置,可能有多个起点,都需要一一尝试. 每轮迭代的时候记得将是否遍历标记数组还原为未遍历的 ...
- 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( ...
- Network Saboteur (深搜递归思想的特殊使用)
个人心得:对于深搜的使用还是不到位,对于递归的含义还是不太清楚!本来想着用深搜构成一个排列,然后从一到n分割成俩个数组,然后后面发现根本实现不了,思路太混乱.后来借鉴了网上的思想,发现用数组来标志,当 ...
随机推荐
- top batch output
echo 3 > sudo tee /proc/sys/vm/drop_caches top -d30 -bn20 > a
- java中的URL InetAddress类
/* * InetAddress类: * 用于标识网络上的硬件资源,表示互联网协议(ip)地址,是java对ip地址的封装. * 其实例对象包含以数字形式保存的IP地址,主机名. * InetAddr ...
- C#项目间循环引用的解决办法,有图有真相
C#项目间循环引用的解决办法,有图有真相 程序间的互相调用接口,c#禁止互相引用,海宏软件,20160315 /// c#禁止互相引用,如果项目[订单]中有一个orderEdit单元,要在项目[进销存 ...
- 使用vscode对c进行调试
最近在学习C语言.知道vscode支持对c语言的代码的调试,就想试试.然后找了教程: https://code.visualstudio.com/docs/languages/cpp http://w ...
- HTML5本地存储详解
HTML5storage提供了一种方式让网站能够把信息存储到你本地的计算机上,并再以后需要的时候进行获取.这个概念和cookie相似,区别是它是为了更大容量存储设计的.Cookie的大小是受限的,并且 ...
- LeetCode-448. Find All Numbers Disappeared in an Array C#
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
- SweetTips: 快意灵动的Android提示库!
此文章是我在简书的文章,自行搬到博客园.简书地址:SweetTips: 快意灵动的Android提示库! 源码及所在DEMO已上传至GitHub:SweetTips,欢迎大家提Bug,喜欢的话记得St ...
- 从NPM到CNPM
从NPM到CNPM 原文 http://www.cnblogs.com/hufeng/p/5166479.html 主题 npm 引用NPM网站上的一句话:npm loves you ! NPM ...
- Express ( MiddleWare/中间件 路由 在 Express 中使用模板引擎 常用API
A fast, un-opinionated, minimalist web framework for Node.js applications. In general, prefer simply ...
- oracle 删除当前用户下所有的表、索引、序列...
select 'drop table "' || table_name ||'";'||chr(13)||chr(10) from user_tables; --delete t ...