Codeforces 101206 I & HDU 6007 Mr. Panda and Crystal

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include<vector>
#include <functional>
using namespace std;

#define sp system("pause")

typedef long long ll;
typedef pair<int, ll>pii;
typedef bitset<101> bs;

struct cmp
{
bool operator()(const pii &x, const pii &y)
{
return x.second > y.second;
}
};

const int MAXN = 250;
const int MAXM = 100000 + 10;
const int INF = 1e8;

int m, n, k;
int p[MAXN], c[MAXN];
vector<pii>K[MAXN];
vector<int>B[MAXN];
ll dist[MAXN];
priority_queue<pii, vector<pii>, cmp>pq;
ll dp[MAXM];

void init()
{
for (int i = 0; i < MAXN; i++)K[i].clear(),dist[i]=INF,B[i].clear();
while (pq.size())pq.pop();
memset(dp, -1, sizeof dp);
}

int main()
{
int T;
cin >> T;
int cas = 1;
while (T--)
{
init();
scanf("%d%d%d", &m, &n, &k);
for (int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
if (x == 0)scanf("%d", p + i), c[i] = INF;
else scanf("%d%d", c + i, p + i);
}
for (int i = 0; i < k; i++)
{
int x, y;
scanf("%d%d", &x, &y);
x--;
K[i].push_back(pii(x, 1));
for (int j = 0; j < y; j++)
{
int xx, yy;
scanf("%d%d", &xx, &yy);
xx--;
K[i].push_back(pii(xx, yy));
B[xx].push_back(i);
}
}
for (int i = 0; i < n; i++)
{
dist[i] = c[i];
pq.push(pii(i, dist[i]));
}
while (pq.size())
{
pii t = pq.top();
pq.pop();
int u = t.first;
int d = t.second;
if (d > dist[u])continue;
for (int i = 0; i < B[u].size(); i++)
{
int tk = B[u][i];
int v = K[tk][0].first;
ll up = 0;
for (int j = 1; j < K[tk].size(); j++)
{
up += dist[K[tk][j].first] * K[tk][j].second;
}
if (up < dist[v])
{
dist[v] = up;
pq.push(pii(v, dist[v]));
}
}
}
dp[0] = 0;
ll maxx = 0;
for (int i = 0; i <= m; i++)
{
if (dp[i] == -1)continue;
for (int j = 0; j < n; j++)
{
if (i + dist[j] <= m)
{
if (dp[i + dist[j]] == -1)dp[i + dist[j]] = dp[i] + p[j];
else dp[i + dist[j]] = max(dp[i + dist[j]], dp[i] + p[j]);
}
}
maxx = max(maxx, dp[i]);

}
printf("Case #%d: %I64d\n", cas++, maxx);
}
}

10-02 231

03-22 1000

07-03 1157

04-29 2880

10-22 439

11-07 247

10-29 110

11-13 242

04-02 1466

HDU 6007 Mr. Panda and Crystal (最短路 + 完全背包)

©️2020 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

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