Ural1353--dp--milliard Vasya ' s Function

Source: Internet
Author: User


Vasya is the beginning mathematician. He decided to make a important contribution to the science and to become famous all over the world. But what can he do and if the most interesting facts such as Pythagor ' s theorem is 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) is rather simple:the value of the NTh VF in the point Sis a amount of integers from 1 to NThat has the sum of digits S. You seem to is great programmers, so Vasya gave a task to find the milliard VF value (i.e. the VF with N= 9) Because Vasya himself won ' t cope with the task. Can You solve the problem?


Integer S(1≤ S≤81).


The milliard VF value in the S.

Sample Input

input Output
The main idea: ask you from 1 to 10^9 the number of all bits added to S is how many of us define DP[I][J] to represent the sum of the number of I bits and for J, then you can get the state transfer equation dp[i][j] = dp[i-1][j] + dp[i-1][j-1] + ... dp[i-1][ J-9] Of course meet j-9 >= 0 because consider is the current state and the original state of the change, the state as a whole, to insert just an element, dp[i-1][j] means to enter 0, the other means to insert K, consider when s = 1 o'clock, to add 1
#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int dp[10][85];int Main ( ) {    int S;    Memset (Dp,0,sizeof (DP));    for (int i = 1; I <= 9; i++)        dp[1][i] = 1;    for (int i = 2, I <= 9; i++) {for        (int j = 1; J <= Bayi; j + +) {            dp[i][j] = dp[i-1][j];                for (int k = 1; k <= 9 &&  k <= J; k++) {                    Dp[i][j] + = dp[i-1][j-k]                ;    }} while (~SCANF ("%d", &s)) {        int ans = 0;        if (S = = 1) {printf ("10\n"); continue;}        for (int i = 1; I <= 9;i++)            ans + = dp[i][s];        printf ("%d\n", ans);    }    return 0;}


Ural1353--dp--milliard Vasya ' s Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.