思路:

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,st=1,a[6666],b[6666],l,r,ans,vis[6666],Mid,tot,sum[6666];
bool dfs(int x,int pos,int waste){
if(!x)return 1;
if(waste+sum[Mid]>tot)return 0;
bool flag=0;
for(int i=pos;i<=m;i++)
if(a[i]-b[x]>=0){
a[i]-=b[x];
if(a[i]<b[1])waste+=a[i];
if(b[x]==b[x-1])flag=dfs(x-1,i,waste);
else flag=dfs(x-1,1,waste);
if(a[i]<b[1])waste-=a[i];
a[i]+=b[x];
if(flag)return 1;
}
return 0;
}
int main(){
scanf("%d",&m);
for(int i=1;i<=m;i++)scanf("%d",&a[i]);
sort(a+1,a+1+m);
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&b[i]);
sort(b+1,b+1+n);
while(b[n]>a[m])n--;
for(int i=1;i<=n;i++)sum[i]=sum[i-1]+b[i];
while(a[st]<b[1])st++;
for(int i=st;i<=m;i++)a[i-st+1]=a[i],tot+=a[i-st+1];
m=m-st+1;
l=0,r=n;
while(l<=r){
Mid=(l+r)>>1;
if(dfs(Mid,1,0))ans=Mid,l=Mid+1;
else r=Mid-1;
}
printf("%d\n",ans);
}

BZOJ 1082 暴搜的更多相关文章

  1. BZOJ 1193 [HNOI2006]马步距离:大范围贪心 小范围暴搜

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1193 题意: 给定起点(px,py).终点(sx,sy).(x,y < 100000 ...

  2. bzoj 1053 [ HAOI 2007 ] 反素数ant ——暴搜

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1053 试图打表找规律,但无果... 看TJ了,暴搜: 注意参数 w 是 long long. ...

  3. [bzoj]1053反质数<暴搜>

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1053 感想:这道题拿到以后还是想去知道一个数的约数个数要怎么求,去网上搜了公式,但是还是没有思 ...

  4. [BZOJ 1082] [SCOI2005] 栅栏 【二分 + DFS验证(有效剪枝)】

    题目链接:BZOJ - 1082 题目分析 二分 + DFS验证. 二分到一个 mid ,验证能否选 mid 个根木棍,显然要选最小的 mid 根. 使用 DFS 验证,因为贪心地想一下,要尽量先用提 ...

  5. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] ...

  6. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

  7. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  8. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  9. Sicily1317-Sudoku-位运算暴搜

    最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...

随机推荐

  1. 11g Oracle Rac安装(基于linux6)可能出现的问题

    11g Oracle Rac安装(基于linux6)可能出现的问题汇总: 7)使用"yum"命令执行节点的自动配置失败. 修改一下 /etc/resolv.conf,添加: nam ...

  2. 【BZOJ 1406】 [AHOI2007]密码箱

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] \(x^2%n=1\) \(x^2-1 = k*n\) \((x+1)*(x-1) % n == 0\) 设\(n=a*b\) 对于 ...

  3. 转:强制Visual Studio以管理员身份运行

    Windows 8的一个既安全又蛋疼之处是UAC的行为被改变了.以往在Windows 7中,只要关闭了UAC,自己的帐号又是本机管理员组的,任何程序都会以管理员身份启动.然而,在Windows 8上, ...

  4. 实现图像剪裁 jquery.Jcrop

       配合 jquery.Jcrop 实现上传图片进行剪裁保存功能    <script src="js/jquery.min.js"></script> ...

  5. hdu 4841 圆桌问题(用vector模拟约瑟夫环)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4841 圆桌问题 Time Limit: 3000/1000 MS (Java/Others)    M ...

  6. Vue源代码笔记(一)数据绑定

    VUE数据绑定介绍 数据绑定是vue的基础核心之一,本文以Vue对象(当然也包含VueComponent)里的data数据绑定为例,阐述整个绑定的过程. Vue的数据绑定由三部分组成, Observe ...

  7. less03 混合

    less //基本混合 .font_hn{ color: red; font-family: microsoft yahei, "黑体", Arial, Simsun, " ...

  8. BZOJ 3240 构造矩阵+矩阵快速幂

    思路: ax+b cx+d 构造矩阵+矩阵快速幂 (需要加各种特判,,,,我好像加少了- ) //By SiriusRen #include <cstdio> #include <c ...

  9. android取高度

    Rect rect = new Rect();  getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);  int top = r ...

  10. C#后台请求其它网站页面

    /// <summary> /// 指定Post地址使用Get 方式获取全部字符串 /// </summary> /// <param name="url&qu ...