POJ3181

Dollar Dayz

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3923   Accepted: 1530

Description

Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5
tools at $1 each or 1 tool at $3 and an additional 1 tool at $2. Of course, there are other combinations for a total of 5 different ways FJ can spend all his money on tools. Here they are:

        1 @ US$3 + 1 @ US$2

        1 @ US$3 + 2 @ US$1

        1 @ US$2 + 3 @ US$1

        2 @ US$2 + 1 @ US$1

        5 @ US$1

Write a program than will compute the number of ways FJ can spend N dollars (1 <= N <= 1000) at The Cow Store for tools on sale with a cost of $1..$K (1 <= K <= 100).

Input

A single line with two space-separated integers: N and K.

Output

A single line with a single integer that is the number of unique ways FJ can spend his money.

Sample Input

5 3

Sample Output

5

Source

就是整数划分的模板题,只是输出的结果比较打,高精度用数组储存。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const __int64 MD=10000000000;
struct node
{
    __int64 g[5];
    node friend operator +(node a,node b)
    {
        node c;
        int i;
        for(i=0;i<5;i++)
        {
            c.g[i]=a.g[i]+b.g[i];
        }
        for(i=0;i<5;i++)
        {
            if(c.g[i]>=MD)
            {
                c.g[i+1]+=c.g[i]/MD;
                c.g[i]%=MD;
            }
        }
        return c;
    }
    void friend shuchu(node a)
    {
        int i;
        for(i=4;i>=0&&a.g[i]==0;i--);
        printf("%I64d",a.g[i]);
        for(i--;i>=0;i--)
        {
            printf("%010I64d",a.g[i]);
        }
        printf("\n");
    }
};
node dp[1001][101];
int main()
{

    int n,k,i,j,x;
    for(i=0;i<1001;i++)
        for(j=0;j<101;j++)
            for(x=0;x<5;x++)
                dp[i][j].g[x]=0;
    for(i=1;i<1001;i++)
        dp[i][1].g[0]=1;
    for(i=1;i<101;i++)
        dp[1][i].g[0]=1;
        dp[0][0].g[0]=1;
    for(i=2;i<1001;i++)
    {
        for(j=2;j<101;j++)
        {
            if(i==j)
                dp[i][j]=dp[i][i-1]+dp[0][0];
            else if(i<j)
                dp[i][j]=dp[i][i];
            else
                dp[i][j]=dp[i][j-1]+dp[i-j][j];
        }
    }
     //cout<<dp[5][3].g[0]<<endl;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
       shuchu(dp[n][k]);
    }
    return 0;
}

POJ3181

时间: 2024-10-10 21:25:05

POJ3181的相关文章

Dollar Dayz poj3181

http://poj.org/problem?id=3181 这个题目一开始就能看出来是个dp问题,但是我并没有一开始就看出来是一个完全背包为题,只是想着根据以前的方法,这个问题应该是可以找到规律的,但是,还是被坑了,这还是一个大数问题! 首先我膜拜一下hankcs大神的: /////////////////////////////////////////////////////////// #include <iostream> using namespace std; unsigned l

POJ3181——DP(找钱3)——Dollar Dayz

Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1

[POJ3181] Dollar Dayz

Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1

poj3181 Dollar Dayz (DP+大数)

Dollar Dayz Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3181 Appoint description: System Crawler (2016-05-27) Description Farmer John goes to Dollar Da

POJ3181 Dollar Dayz 【母函数】+【高精度】

Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4204   Accepted: 1635 Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are sell

poj3181 背包+大数

http://poj.org/problem?id=3181 Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7997   Accepted: 2992 Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his

4月23日

poj3181 题意:问用1到k组成n共有多少种组成方法 分析:用dp[i][j]纪录前i种数相加得到j共有多少种方法 (1)若j-i>=0,dp[i][j]=dp[i-1][j]+dp[i][j-i] (2)dp[i][j]=dp[i-1][j] 注意这个地方会爆long long,要用高精度,用java大数类写了一个高精度 1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 //poj3181 5 public cla

week0

Time: 2014.4.21~2014.4.27 poj3176 题意:数塔 思路:dp[i][j]=max(dp[i-1][j-1],dp[i-1][j])+a[i][j]; Code: poj3176.cpp poj2229 题意:仅用1,2,4,8...组成n的方案数对10^9取余 思路:n为奇数 dp[n]=dp[n-1] (写成 dp[n]=dp[n-1]+dp[n-2]+dp[n-4]+... 的话想想,是不是会算重) 同理,n为偶数 dp[n]=dp[n-1]+dp[n/2] (