URAL 1353 Milliard Vasya's Function(数位DP)
来源:互联网 发布:《梦里花落知多少》txt 编辑:程序博客网 时间:2024/06/06 05:09
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
1
10
设右区间为1e9直接数位DP即可。
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<bitset>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int INF = 0x3f3f3f3f;LL dp[10][100];int s;int num[]={0,0,0,0,0,0,0,0,0,0,1};LL dfs(int pos,int sum,int flag){ if(pos==0) return sum==0; if(!flag&&dp[pos][sum]!=-1) return dp[pos][sum]; int ed=flag?num[pos]:9; LL res=0; for(int i=0;i<=ed;i++) res+=dfs(pos-1,sum-i,flag&&i==ed); if(!flag) dp[pos][sum]=res; return res;}int main(){ while(~scanf("%d",&s)) { CLEAR(dp,-1); LL ans=dfs(10,s,1); printf("%lld\n",ans); } return 0;}/**/
0 0
- URAL 1353 Milliard Vasya's Function(数位DP)
- URAL 1353 Milliard Vasya's Function(DP)
- Ural 1353 Milliard Vasya's Function(DP)
- URAL 1353. Milliard Vasya's Function(dp)
- ural 1353. Milliard Vasya's Function(dp)
- URAL 1353Milliard Vasya's Function dp练习
- Ural 1353 Milliard Vasya's Function
- URAL1353---Milliard Vasya's Function(简单数位dp)
- Ural 1353. Milliard Vasya's Function 暴搜
- ural 1353. Milliard Vasya's Function
- ural 1353. Milliard Vasya's Function
- ural 1353. Milliard Vasya's Function
- Milliard Vasya's Function
- timus 1353. Milliard Vasya's Function 解题报告 URAL
- Milliard Vasya's Function(Ural_1353)
- Ural1353-Milliard Vasya's Function
- HOJ 10444 The milliard Vasya's function(简单背包)
- hnu 10444 The milliard Vasya's function(母函数)
- sqlite3常用命令
- hacker发展流程图 菜菜学习中
- RESTful API 设计最佳实践
- UVA 11916 Emoogle Grid(模指数方程)
- 什麼是REST跟RESTful?
- URAL 1353 Milliard Vasya's Function(数位DP)
- C语言类型强制转换
- Evaluate Reverse Polish Notation
- 文章标题
- 2011 Asia Fuzhou Regional Contest
- [leetCode] Rotate Array
- C/C++ 数字转化为字符串函数
- MySQL优化必须调整的10项配置
- 竖着显示的“UIPageControl”