Problem I. Mr. Panda and Crystal
来源:互联网 发布:数据预处理的方法 编辑:程序博客网 时间:2024/06/03 12:13
搜索加背包 。
#include <bits/stdc++.h>using namespace std;#define mk make_pair#define pus push_backvector<pair<int ,int > > de[205][205];int dej[205];int be[205];int bj[205];int jl[205];int dp[10005];int s,n,m;struct node{ int z; int x,y;} d[2005];void dfs(int node){ if(bj[node]) return ; be[node]=min(be[node],d[node].x); bj[node]=1; for(int j=0;j<dej[node];j++) { int ans=10005; if(de[node][j].size()) ans=0; for(int i=0;i<de[node][j].size();i++) { int x=de[node][j][i].first; int y=de[node][j][i].second; dfs(x); ans+=be[x]*y; if(ans>s) break; } be[node]=min(be[node],ans); }}int main(){ int t; //cin>>t; scanf("%d",&t); int le=1; while(t--) { //cin>>s>>n>>m; scanf("%d%d%d",&s,&n,&m); for(int i=0;i<205;i++) { d[i].x=d[i].y=10005; } memset(dej,0,sizeof(dej)); memset(be,100,sizeof(be)); memset(bj,0,sizeof(bj)); memset(jl,0,sizeof(jl)); //cout<<be[0]<<endl; for(int i=0;i<205;i++) { for(int j=0;j<205;j++) { de[i][j].clear(); } } for(int i=1;i<=n;i++) { // cin>>d[i].z; scanf("%d",&d[i].z); if(d[i].z) { //cin>>d[i].x>>d[i].y; scanf("%d%d",&d[i].x,&d[i].y); } else { //cin>>d[i].y; scanf("%d",&d[i].y); } be[i]=d[i].x; } int x,y; for(int i=0;i<m;i++) { // cin>>x>>y; scanf("%d%d",&x,&y); jl[i]=x; int a,b; for(int j=0;j<y;j++) { //cin>>a>>b; scanf("%d%d",&a,&b); de[x][dej[x]].pus(mk(a,b)); } dej[x]++; } for(int i=0;i<m;i++) dfs(jl[i]); // for(int i=1;i<=n;i++) cout<<i<<' '<<be[i]<<endl; memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { if(be[i]<=s) for(int j=be[i];j<=s;j++) { dp[j]=max(dp[j],dp[j-be[i]]+d[i].y); } } cout<<"Case #"<<le++<<": "<<dp[s]<<endl; }}
阅读全文
0 0
- Problem I. Mr. Panda and Crystal
- Codeforces 101206 I & HDU 6007 Mr. Panda and Crystal
- HDU6007-Mr. Panda and Crystal
- Mr. Panda and Crystal HDU
- HDU 6007 Mr. Panda and Crystal (最短路 + 完全背包)
- hdu 6007 Mr. Panda and Crystal(最短路+完全背包)
- Hdu 6007 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
- Blog10@linux网络配置及路由搭建
- Ubuntu 安装 opencv2.4.9
- 配置
- 关于继承父类的初始化方法
- 1、js原生实现移动端手指滑动轮播图效果
- Problem I. Mr. Panda and Crystal
- leetcode_463. Island Perimeter ? 待解决
- 打破关住自己的门
- 海阔凭鱼跃天高任鸟飞
- Java 基础练习之数组
- 图片上传前端预览兼容ie9以下
- Beaglebone Black使用记录
- 多态心得(java课上)
- PullToRefresh实现下拉刷新,,上拉加载