【HDU 5887】Herbs Gathering(dfs+时间剪枝)
来源:互联网 发布:手机怎么绑定淘宝小号 编辑:程序博客网 时间:2024/06/10 06:00
【HDU 5887】Herbs Gathering(dfs+时间剪枝)
题目大意:
n个物体 每个物品有体积和价值,取V体积问最大价值。
背包,不过数据很大……
然后……先写个暴力的dfs,TLE
然后按性价比排个序,TLE
然后加各种剪枝,TLE
赛后(clock()-st)/CLOCKS_PER_SEC <= 0.02 st为dfs前取的clock()
跑的比谁都快……不想说话。。
代码如下:
#include <iostream>#include <cmath>#include <vector>#include <cstdlib>#include <cstdio>#include <climits>#include <ctime>#include <cstring>#include <queue>#include <stack>#include <list>#include <algorithm>#include <map>#include <set>#define LL long long#define Pr pair<int,int>#define fread(ch) freopen(ch,"r",stdin)#define fwrite(ch) freopen(ch,"w",stdout)using namespace std;const int INF = 0x3f3f3f3f;const int msz = 10000;const int mod = 1e9+7;const double eps = 1e-8;struct Obj{ LL v,w; double xjb; bool operator < (const struct Obj a)const { return xjb > a.xjb; }} obj[111];int n;LL v,mn;LL ans;double c;void dfs(int pos,LL sum,LL v){ if((clock()-c)/CLOCKS_PER_SEC > 0.02) return; ans = max(ans,sum); if(sum+obj[pos].xjb*v < ans) return; if(v < mn) return; if(pos == n) return; if(obj[pos].v <= v) dfs(pos+1,sum+obj[pos].w,v-obj[pos].v); dfs(pos+1,sum,v);}int main(){ //fread(""); //fwrite(""); while(~scanf("%d%lld",&n,&v)) { mn = 1e9+7; for(int i = 0; i < n; ++i) { scanf("%lld%lld",&obj[i].v,&obj[i].w); obj[i].xjb = obj[i].w*1.0/obj[i].v; mn = min(mn,obj[i].v); } sort(obj,obj+n); ans = 0; c = clock(); dfs(0,0,v); printf("%lld\n",ans); } return 0;}
1 0
- 【HDU 5887】Herbs Gathering(dfs+时间剪枝)
- HDU 5887 Herbs Gathering(搜索+剪枝)
- hdu 5887 Herbs Gathering【dfs+贪心】
- HDU 5887 Herbs Gathering (超大01背包|dfs+剪枝|map|卡时)
- hdu 5887 Herbs Gathering
- HDU 5887 Herbs Gathering 01背包+DFS搜索 *
- HDU 5887 Herbs Gathering(01背包搜索)
- hdu5887 Herbs Gathering(搜索)
- Herbs Gathering 大背包 (n<=100 W<=10^9) 深搜+最优化剪枝
- hdu 5887 herb gathering 搜索剪枝
- hdu5887 Herbs Gathering
- HDOJ 5887 Herbs Gathering 【2016青岛网赛】DP+MAP
- hdu 1010 (DFS+剪枝)
- hdu 1455 (DFS+剪枝)
- hdu5887 Herbs Gathering 搜索01背包
- HDU 1010(搜索题,DFS+剪枝)
- HDU 1010( DFS+奇偶剪枝)
- HDU 1010 Dfs的精华(剪枝)
- Android---不注意的小细节
- 顺序表应用7:最大子段和之分治递归法
- Material Design TabLayout篇
- JAVA进阶4.8——Vector和Stack
- java and python学习——第三周leetcode刷题
- 【HDU 5887】Herbs Gathering(dfs+时间剪枝)
- 设置编码为UTF8
- 设计模式之策略模式
- tableview 展示小视频
- 关于安装QT VS2013中我遇到的各种问题
- 积分通道特征代码调试
- 逆向分析人员常用的快捷键
- Endnote x7.5 破解 注册 激活方法
- JSONObject/JSONArray解析json