VF

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述
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 digits S. 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?
输入
There are multiple test cases.
Integer S (1 ≤ S ≤ 81).
输出
The milliard VF value in the point S.
样例输入
1
样例输出
10
动态规划!
如果找不到状态转移方程,直接递归求值,再打表!别怕麻烦哦!
递归代码:
#include<stdio.h>
#include<string.h>
#define M 1000000000
__int64 num[85];
void fun(__int64 a,__int64 sum,__int64 m)
{if(sum>M)return;__int64 i;num[m]++;for(i=0;i<=9;i++){fun(i,sum*10+i,m+i);}
}
int main()
{__int64 n,i;memset(num,0,sizeof(num));for(i=1;i<=9;i++){fun(i,i,i);}while(~scanf("%I64d",&n)){printf("%I64d\n",num[n]);}return 0;
}
打表:
AC码:
#include<stdio.h>
int f[82]={1,10,45,165,495,1287,3003,6435,12870,24310,43749,75501,125565,202005,315315,478731,708444,1023660,1446445,2001285,2714319,3612231,4720815,6063255,7658190,9517662,11645073,14033305,16663185,19502505,22505751,25614639,28759500,31861500,34835625,37594305,40051495,42126975,43750575,44865975,45433800,45433800,44865975,43750575,42126975,40051495,37594305,34835625,31861500,28759500,25614639,22505751,19502505,16663185,14033305,11645073,9517662,7658190,6063255,4720815,3612231,2714319,2001285,1446445,1023660,708444,478731,315315,202005,125565,75501,43749,24310,12870,6435,3003,1287,495,165,45,9,1};
int main()
{int n;while(~scanf("%d",&n)){printf("%d\n",f[n]);}return 0;
}
动态规划!
AC码:
#include<stdio.h>
int dp[10][82];
void DP()
{int i,j,k;for(i=1;i<10;i++)dp[1][i]=1;for(i=1;i<10;i++){// i表示有i位数字时for(j=1;j<=9*i;j++){// j表示变化范围,当有i位数时,j的范围[1,9*i]for(k=0;k<10&&k<=j;k++){dp[i][j]+=dp[i-1][j-k];}}}
}
int main()
{int n,i,ans;DP();while(~scanf("%d",&n)){if(n==1)printf("10\n");else{ans=0;for(i=1;i<10;i++)ans+=dp[i][n];printf("%d\n",ans);}}return 0;
}

NYOJ 269 VF相关推荐

  1. nyoj 269 VF 动规

    VF 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 Vasya is the beginning mathematician. He decided to make a ...

  2. c语言:输入一个字符串,统计字母,数字,空格出现的个数,c - 统计字符串字母,空格,数字,其他字符的个数和行数....

    #include #include using namespace std; /* 题目:输入一行字符,分别统计出其中英文字母.空格.数字和其它字符的个数. */ void count() { //统 ...

  3. NYOJ 30 Gone Fishing JAVA+解析

    Gone Fishing这道题目运用的多次折合成一次这种思想我首次见,我想的一个思路是,每次算一下鱼量和时间代价比,这个代码我没有敲,下面的代码是一位仁兄敲得,我研读了一下,做了一个注释,应该有利于后 ...

  4. Manacher算法 , 实例 详解 . NYOJ 最长回文

    51 Nod http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1089 Manacher 算法 定义数组 p[i]表示以i为 ...

  5. NYOJ 527 AC_mm玩dota

    AC_mm玩dota 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 大家都知道AC_mm比较喜欢玩游戏,特别是擅长war3这款经典游戏.某天AC_mm来到了VS平台上 ...

  6. 全国计算机二级考试vf知识点总结,VF全国计算机等级考试二级公共基础知识点总结.doc...

    VF全国计算机等级考试二级公共基础知识点总结 第一章数据结构与算法 算法的基本特征:可行性,确定性,有穷性,拥有足够的情报. 算法的三种基本控制结构:顺序,选择,循环. 算法的复杂度主要包括:时间复杂 ...

  7. hdu-2204 Eddy's爱好 nyoj 526

    hdu : http://acm.hdu.edu.cn/showproblem.php?pid=2204 nyoj :  http://acm.nyist.net/JudgeOnline/proble ...

  8. NYOJ 762 第k个互质数(二分 + 容斥)

    第k个互质数 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 两个数的a,b的gcd为1,即a,b互质,现在给你一个数m,你知道与它互质的第k个数是多少吗?与m互质的数按 ...

  9. NYOJ 257 中缀表达式表示成后缀表达式

    话说这道题代码那个丑陋啊,,写出来我自己都不想再看第二遍啊...看了看聪神的代码,还消耗我3个NYOJ币啊,,更扯得是,聪神的代码我看不懂啊,,,,卧槽...这道题不再多说了,数据结构上有详细的介绍, ...

最新文章

  1. 查看mysql版本不一致_MySQL-版本不一致
  2. 15g1和g2和g3区别大吗_河南成人高考和普通高考的区别有哪些?成人高考难度会越来越大吗?...
  3. java.library.path hadoop_java - Hadoop“无法为您的平台加载native-hadoop库”警告
  4. 7-spark学习笔记-spark性能调优
  5. linux安装autossh详细教程,在Linux下安装autossh的教程
  6. MapReduce运行机制
  7. Adobe illustrator 剪切蒙版圆形细胞培养皿 - 连载20
  8. torch.cuda.FloatTensor 与 torch.FloatTensor(torch.Tensor)--CPU和GPU上的数据类型
  9. 【nexus】nexus 仓库组的概念 以及相关配置 代码发布相关
  10. .NET 内存管理与垃圾回收:实现IDisposable接口和析构函数
  11. 【报告分享】2021年00后生活方式洞察报告.pdf(附下载链接)
  12. 零基础可上手 | 手把手教你用Cloud AutoML做毒蜘蛛分类器
  13. Android通过post请求发送一个xml,解析返回xml数据
  14. 国家基本比例尺地图图式
  15. 是否可以将现有图表导入到 think-cell?
  16. spyder5 更改为简体中文的方法,与spyder4不同
  17. 关于app inventor跨界面连接蓝牙并且一键SOS拨打电话求救(三)
  18. idea java 语法高亮_Intellij IDEA 中JAVA常用配置项总结
  19. 记录写博文用到的一些工具
  20. 弹幕视频网站的盈利模式 ——以哔哩哔哩弹幕网为例

热门文章

  1. 快速打开IIS的方法
  2. 哈希是什么?为什么哈希存取比较快?
  3. nodejs链接kafka示例(producer、consumer)
  4. Java_Notes_基础排序总结与对比
  5. 会声会影如何渲染高清视频
  6. 新兴短距离无线通信技术ZigBee入门到进阶
  7. Daily scrum[2013.11.28]
  8. 实验一 小凡和VMware虚拟机的使用练习
  9. 空集的cardinality是0
  10. Confluence 6 升级完成后的检查