BZOJ 1082: [SCOI2005]栅栏|二分答案爆搜
2016-01-21 11:02
316 查看
爆搜一定要有技术含量,我这种只会无脑的爆搜要T到死TTTT
#include<set> #include<map> #include<ctime> #include<queue> #include<cmath> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define T 1006 #define MX 1e9 using namespace std; int sc() { int i=0,f=1; char c=getchar(); while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9')i=i*10+c-'0',c=getchar(); return i*f; } int h[55],nd[T],sum[T],bl[T],n,m,S,mid; bool dfs(int x,int y,int rest) { if(y==0)return 1; while(x<=n&&h[x]<nd[1])rest+=h[x],x++; if(sum[mid]>S-rest)return 0; int t=x; if(nd[y]==nd[y+1]&&y!=mid)t=bl[y+1]; for(int i=t;i<=n;i++) if(h[i]>=nd[y]) { bl[y]=i; h[i]-=nd[y]; if(dfs(x,y-1,rest)) { h[i]+=nd[y]; return 1; } else h[i]+=nd[y]; } return 0; } int main() { n=sc();for(int i=1;i<=n;i++)h[i]=sc(),S+=h[i]; m=sc();for(int i=1;i<=m;i++)nd[i]=sc(); sort(h+1,h+n+1),sort(nd+1,nd+m+1); while(nd[m]>h )m--; for(int i=1;i<=m;i++)sum[i]=sum[i-1]+nd[i]; int l=0,r=m,ans=0; while(l<=r) { mid=l+r>>1; if(dfs(1,mid,0))ans=mid,l=mid+1; else r=mid-1; } cout<<ans; return 0; }
相关文章推荐
- UESTC - 1707 神秘组织的的分数
- 【PA2015】【BZOJ4294】Fibonacci
- NOIP历年搜索整理
- NOIP2011 mayan游戏 解题报告(搜索)
- NOIP 2000单词接龙 解题报告(爆搜)
- 如何用angularjs制作一个完整的表格
- 【Android】直接利用View创建Dialog
- python实现简单爬虫功能
- bzoj2039: [2009国家集训队]employ人员雇佣
- not operator in C++ for int
- 动态创建OATipBean
- POJ3268(最短路)
- 新版Matlab中神经网络训练函数Newff的使用方法
- C#内存分配学习
- You need to use a Theme.AppCompat theme (or descendant) with this activity错误解决
- c++11 thread 封装线程类
- vi指令一览
- 文件操作
- LNMP环境下crontab问题
- MySQL索引类型