H. The Boomsday Project

题意:租共享单车,每次r元,可以买卡,卡的有效期为d天,可用次数为k次,费用为c元,每次买新卡会覆盖旧卡,现有n种买卡的方案,m天需要骑车,其中这m天,第pi天需要骑车qi次。问最小费用。
题解:关于第i天可能使用的骑车方案不是同一种,所以,干脆不要看每一天用哪一种方案了,而是每一次骑车用哪种方案。

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <vector>
#define ll long long
#define ms(a, b) memset(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define Size(a) int((a).size())
#define all(x) x.begin(), x.end()
#define ull unsigned long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)
#define endl "\n"
#define bug cout << "----acac----" << endl;
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
ll ksm(ll a, ll b, ll mod)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)
        {
            ans = (a % mod * ans % mod) % mod;
        }
        b >>= 1;
        a = (a % mod * a % mod) % mod;
    }
    return ans;
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll read()
{
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
const ll mod = 998244353;
const int maxn = 2e6 + 10;
const int N = 2e5 + 10;
const int maxm = 5e3 + 50;
const double eps = 1e-8;
const ll inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1);
int n, m, r;
map<int, int> p;
struct node
{
    int d, k, c;
} a[maxn];
int v[maxn];
ll dp[maxn];
int pre[maxn];//表示第i种方案最后一次使用时在第几次骑车
int main()
{
    IOS;
    cin >> n >> m >> r;
    for (int i = 1; i <= n;i++)
    {
        pre[i] = 1;
        cin >> a[i].d >> a[i].k >> a[i].c;
    }
    int cnt = 0;
    for (int i = 1; i <= m;i++)
    {
        int x, y;
        cin >> x >> y;
        while(y--)
        {
            v[++cnt] = x;//第i次骑车是第几天
        }
    }
    sort(v + 1, v + 1 + cnt);
    for (int i = 1; i <= cnt ;i++)
    {
        dp[i] = dp[i-1]+r;
        for (int j = 1; j <= n;j++)
        {
            while(v[pre[j]]+a[j].d<=v[i]||a[j].k+pre[j]<=i)
                pre[j]++;
            dp[i] = min(dp[i], dp[pre[j] - 1] + a[j].c);
        }
    }
    cout << dp[cnt] << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值