10313 - Pay the Price

题目链接

题意:一直都有0~300这300种价值的金额。

现在有n~1000次询问:

可能给出参数:

以下的n~300
1个:n, 输出可以组成价值n的方式的个数。
2个:n, a输出用硬币个数小于a的价值组成价值n的方式的个数。
3个:n, a, b输出用硬币个数大于a和小于b组成价值n的方式的个数。

题解:每次都要有个数的体现,那么就dp【300】【300】,一定不会多于300张,把张数作为第二维算进去。小细节,a和b为了避免数组越界,必须提前预判。

重点:需要张数从a到b,那么dp再开一维。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctype.h>
#include <limits.h>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#define CLR(a) memset(a, 0, sizeof(a))
#define REP(i, a, b) for(ll i = a;i < b;i++)
#define REP_D(i, a, b) for(ll i = a;i <= b;i++)

typedef long long ll;

using namespace std;

const ll maxn = 300 +10;
ll dp[maxn][maxn], n, tot, l, r;//好像用ll把。。。
ll ans;

void getDp()
{
    tot = 300;
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;//初始化,有一种方法
    for(ll i = 1; i <= tot; i++)//完全背包
    {
        for(ll m = i; m <= tot; m++)//完全背包
        {
            for(ll k = 1; k <= tot; k++)
            {
                dp[m][k] = (dp[m][k]+dp[m-i][k-1]);//转移
            }
        }
    }
}
void solve()
{
    getDp();
    char ch;
    while(scanf("%lld%c", &tot, &ch) != EOF)
    {
        if(ch == '\n')
        {
            l = 0;
            r = 300;
            ans = 0;
            for(ll i = l; i <= r; i++)
            {
                ans += dp[tot][i];
            }
        }
        else
        {
            scanf("%lld%c", &l, &ch);
            if(ch == '\n')
            {
                r = min(300ll, l);
                l = 0;
                ans = 0;
                for(ll i = l; i <= r; i++)
                {
                    ans += dp[tot][i];
                }
            }
            else
            {
                scanf("%lld", &r);
                l = min(300ll, l);
                r = min(300ll, r);
                ans = 0;
                for(ll i = l; i <= r; i++)
                {
                    ans += dp[tot][i];
                }
            }
        }
        printf("%lld\n", ans);
    }
}

int main()
{
    //freopen("4Din.txt", "r", stdin);
    //freopen("4Dout.txt", "w", stdout);
    solve();
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解决这个问题King Julien rules the Madagascar island whose primary crop is coconuts. If the price of coconuts is P , then King Julien’s subjects will demand D(P ) = 1200 − 100P coconuts per week for their own use. The number of coconuts that will be supplied per week by the island’s coconut growers is S(p) = 100P. (a) (2 pts) Calculate the equilibrium price and quantity for coconuts. (b) (2 pts) One day, King Julien decided to tax his subjects in order to collect coconuts for the Royal Larder. The king required that every subject who consumed a coconut would have to pay a coconut to the king as a tax. Thus, if a subject wanted 5 coconuts for himself, he would have to purchase 10 coconuts and give 5 to the king. When the price that is received by the sellers is pS, how much does it cost one of the king’s subjects to get an extra coconut for himself? (c) (3 pts) When the price paid to suppliers is pS, how many coconuts will the king’s subjects demand for their own consumption (as a function of pS)? 2 (d) (2 pts) Under the above coconut tax policy, determine the total number of coconuts demanded per week by King Julien and his subjects as a function of pS. (e) (3 pts) Calculate the equilibrium value of pS, the equilibrium total number of coconuts produced, and the equilibrium total number of coconuts consumed by Julien’s subjects. (f) (5 pts) King Julien’s subjects resented paying the extra coconuts to the king, and whispers of revolution spread through the palace. Worried by the hostile atmosphere, the king changed the coconut tax. Now, the shopkeepers who sold the coconuts would be responsible for paying the tax. For every coconut sold to a consumer, the shopkeeper would have to pay one coconut to the king. For this new policy, calculate the number of coconuts being sold to the consumers, the value per coconuts that the shopkeepers got after paying their tax to the king, and the price payed by the consumers.
最新发布
03-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值