Poj 3181 dollar dayz

Source: Internet
Author: User
Tags dayz

Link: (-_-) ZZ

Long long ago has a store that sells at a price of [1 $... in the range of K $], there are infinite items for each type of price. The current price is N yuan. You need to spend the N yuan to buy the item and find the total number of matching methods for the item you can buy.

Train of Thought: this is the question in the question of the backpack, but it won't be done. Refer to the idea of Daniel.

Code:

#include <stdio.h>#include <string.h>#define inf 10000000000000000int main(){    int i = 0, j = 0, n = 0, k = 0;    __int64 a[1002], b[1002];    while(scanf("%d %d", &n, &k) != EOF )    {        memset(a, 0, sizeof(a));        memset(b, 0, sizeof(b));        a[0] = 1;        for(i = 1; i<=k; i++)            for(j = i; j<=n; j++)            {                b[j] = b[j]+b[j-i]+(a[j]+a[j-i])/inf;                a[j] = (a[j]+a[j-i])%inf;            }        if(b[n]) printf("%I64d", b[n]);        printf("%I64d\n", a[n]);    }    return 0;}

Code:

#include <stdio.h>#include <string.h>int main(){    int i = 0, j = 0, k = 0 , l = 0, n = 0, s = 0;    __int64 dp[1002][10];    while(scanf("%d %d", &n, &k) != EOF )    {        memset(dp, 0, sizeof(dp));        dp[0][0] = 1;        for(i = 1; i<=k; i++)            for(j = i; j<=n; j++)            {                for(l = 0; l<9; l++)                {                    dp[j][l] += dp[j-i][l];                    if(dp[j][l]>10000)                    {                        dp[j][l] %= 10000;                        dp[j][l+1]++;                    }                }            }        i = 8;        while(dp[n][i] == 0)         i--;        printf("%I64d", dp[n][i--]);        while(i>=0)        {            printf("%.4I64d", dp[n][i]);            i--;        }    }    return 0;}

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.