Mr. Panda and Crystal HDU
来源:互联网 发布:计算机前沿技术大数据 编辑:程序博客网 时间:2024/06/01 08:18
应该注意到假如物品的费用可以被缩小的话
那一定是>=材料中最小的物品的费用
所以可以先对每个物品求最小费用
然后再做一个完全背包
#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <queue>#include <cstdio>#include <map>#include <set>#include <utility>#include <stack>#include <cstring>#include <cmath>#include <vector>#include <ctime>#include <bitset>using namespace std;#define pb push_back#define sd(n) scanf("%d",&n)#define sdd(n,m) scanf("%d%d",&n,&m)#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)#define sld(n) scanf("%lld",&n)#define sldd(n,m) scanf("%lld%lld",&n,&m)#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)#define sf(n) scanf("%lf",&n)#define sff(n,m) scanf("%lf%lf",&n,&m)#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)#define ss(str) scanf("%s",str)#define ans() printf("%d",ans)#define ansn() printf("%d\n",ans)#define anss() printf("%d ",ans)#define lans() printf("%lld",ans)#define lanss() printf("%lld ",ans)#define lansn() printf("%lld\n",ans)#define fansn() printf("%.10f\n",ans)#define r0(i,n) for(int i=0;i<(n);++i)#define r1(i,e) for(int i=1;i<=e;++i)#define rn(i,e) for(int i=e;i>=1;--i)#define rsz(i,v) for(int i=0;i<(int)v.size();++i)#define szz(x) ((int)x.size())#define mst(abc,bca) memset(abc,bca,sizeof abc)#define lowbit(a) (a&(-a))#define all(a) a.begin(),a.end()#define pii pair<int,int>#define pli pair<ll,int>#define pll pair<ll,ll>#define mp(aa,bb) make_pair(aa,bb)#define lrt rt<<1#define rrt rt<<1|1#define X first#define Y second#define PI (acos(-1.0))#define sqr(a) ((a)*(a))typedef long long ll;typedef unsigned long long ull;const ll mod = 1000000000+7;const double eps=1e-9;const int inf=0x3f3f3f3f;const ll infl = 10000000000000000;const int maxn= 200+10;const int maxm = 10000+10;//Pretests passedint in(int &ret){ char c; int sgn ; if(c=getchar(),c==EOF)return -1; while(c!='-'&&(c<'0'||c>'9'))c=getchar(); sgn = (c=='-')?-1:1; ret = (c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0'); ret *=sgn; return 1;}int dis[maxn];int money[maxn];bool vis[maxn];struct node{ int x; vector<pii>g;}no[maxn];vector<int>v[maxn];int dp[maxm];int n,m,k;int cal(int q){ int res = 0; rsz(i,no[q].g) { pii p = no[q].g[i]; int a = p.X , b = p.Y; res += dis[a]*b; } return res;}void dij(){ mst(vis,0); priority_queue<pii>q; r1(i,n)if(dis[i]<=m)q.push(mp(-dis[i],i)); while(!q.empty()) { pii p = q.top(); q.pop(); int u = p.Y; if(vis[u])continue; vis[u] = 1; rsz(i,v[u]) { int idx = v[u][i]; int dist = cal(idx); int nt = no[idx].x; if(dis[nt] > dist) { dis[nt] = dist; q.push(mp(-dist,nt)); } } }}int main(){#ifdef LOCAL freopen("input.txt","r",stdin);// freopen("output.txt","w",stdout);#endif // LOCAL int t; sd(t); r1(cas,t) { printf("Case #%d: ",cas);// int n,m,k; sddd(m,n,k); r1(i,n) { int op; sd(op); if(op) { int a,b; sdd(a,b); money[i] = b; dis[i] = a; } else { int x; sd(x); money[i] = x; dis[i] = m+1; } v[i].clear(); } r1(i,k) { no[i].g.clear(); int x,y; sdd(x,y); no[i].x = x; while(y--) { int a,b; sdd(a,b); no[i].g.pb(mp(a,b)); v[a].pb(i); } } dij(); mst(dp,0); for(int i=1;i<=n;++i) { for(int j = dis[i];j<=m;++j) { dp[j] = max(dp[j],dp[j - dis[i] ] + money[i]); } } int ans = dp[m]; ansn(); } return 0;}
阅读全文
0 0
- Mr. Panda and Crystal HDU
- HDU6007-Mr. Panda and Crystal
- HDU 6007 Mr. Panda and Crystal (最短路 + 完全背包)
- hdu 6007 Mr. Panda and Crystal(最短路+完全背包)
- Codeforces 101206 I & HDU 6007 Mr. Panda and Crystal
- Hdu 6007 Mr. Panda and Crystal 最短路+完全背包
- Problem I. Mr. Panda and Crystal
- Gym101194C-Mr. Panda and Strips
- 【Gym】101194J Mr.Panda and TubeMaster
- Gym101194F-Mr. Panda and Fantastic Beasts
- [acm/icpc2016ChinaFinal][CodeforcesGym101194] Mr.Panda and TubeMaster
- [acm/icpc2016ChinaFinal][CodeforcesGym101194] Mr. Panda and Strips 暴力+剪枝
- [acm/icpc2016ChinaFinal][CodeforcesGym101194] Mr. Panda and Fantastic Beasts 后缀自动机
- [acm/icpc2016ChinaFinal][CodeforcesGym101194] Mr.Panda and TubeMaster费用流
- 2016 China Final F Mr. Panda and Fantastic Beasts
- Gym 101194F Mr. Panda and Fantastic Beasts
- BJ模拟 Mr. Panda and Fantastic Beats(广义后缀自动机、trie树上后缀自动机)
- [费用流] ACM-ICPC Asia China-Final Contest J. Mr.Panda and TubeMaster
- 电磁波的产生实验
- Redis为什么使用单进程单线程方式也这么快
- include和require区别
- 欧拉筛法 && 欧拉函数
- Git :git bash 出现vim的时候怎么退出
- Mr. Panda and Crystal HDU
- Android AM命令行启动程序的方法
- linux脚本明明定义了变量,但是引用的时候报错(原因:shell定义变量的时候,“等号”两边不要加空格)
- 欣的无线轮播!
- 创建一个用于上传文件的表单
- 指针和数组的区别
- 注释转换—将C语言注释风格转换为C++注释风格
- 【自考】数据结构之思维导图
- 4484: [Jsoi2015]最小表示