zoukankan      html  css  js  c++  java
  • ny269 VF

    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
    
    
    题意讲解:本题目是让你求10亿个数的每个位数的数字之和为s的,共有都少个;
    例如:和为1的有1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000共有十个;
    题意大概就是如此,输入一个S,然后求出和为s,的共有多少个;
    可以用动态规划来做:
    状态转移方程:

    初始条件:dp[0][j]=1   j=1、2…9

    状态转移方程:

    dp[i][j]表示:和为i,不超过j个数相加的符合条件的数有多少个

    dp[i][j]=sum{dp[i-k][j-1]  k=0、1…9}

    代码如下:
           

     1 #include<iostream>
     2 using namespace std;
     3 int a[83][13];
     4 void fun()
     5 {
     6     int sum,n,i,j,k;
     7     for(i=0;i<=11;i++)
     8         a[0][i]=1;
     9     for(i=1;i<=81;i++)
    10         for(j=1;j<=9;j++)
    11         for(k=0;k<10 && i-k>=0;k++)
    12            if(a[i-k][j-1])
    13                a[i][j]+=a[i-k][j-1];
    14 }
    15 int main()
    16 {
    17     int t;
    18     fun();
    19     while(cin>>t)
    20     {
    21         if(t==1)
    22             cout<<10<<endl;
    23         else
    24         cout<<a[t][9]<<endl;
    25     }
    26     return 0;
    27 }

  • 相关阅读:
    第二章 成员、变量和常量
    Roman To Integer
    Integer To Roman
    Container With Most Water
    搜狗2015前端工程师笔试题
    从网易与淘宝的font-size思考前端设计稿与工作流
    移动端web app自适应布局探索与总结
    CSS 常用代码
    利用 HTML 和 CSS 实现常见的布局
    CSS 尺寸单位
  • 原文地址:https://www.cnblogs.com/lovychen/p/3361963.html
Copyright © 2011-2022 走看看