思路:

//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. 关于__str__的介绍

    在python语言里,__str__一般是格式是这样的. class A: def __str__(self): return "this is in str" 事实上,__str ...

  2. Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程

    2.Lucene3.6.2包介绍,第一个Lucene案例介绍,查看索引信息的工具lukeall介绍,Luke查看的索引库内容,索引查找过程 2014-12-07 23:39 2623人阅读 评论(0) ...

  3. Eclipse WEB项目更改项目名

    可能很多人都碰到过 WEB 项目需要改名字的事情,不过不是每个人都能很顺畅地完成这个事情.这里简单给大家介绍两种改项目名的方法 1. 在Eclipse 中修改项目名 没错这种方法跟你预料的一样简单,当 ...

  4. LeetCode——Longest Common Prefix

    Write a function to find the longest common prefix string amongst an array of strings. 写一个函数找出字符串数组中 ...

  5. maven手动增加jar文件

    maven手动增加jar文件 在cmd界面输入: mvn install:install-file -Dfile=D:\com.ibm.mq.jar -DgroupId=com.ibm.mq -Dar ...

  6. 重写MPAndroidChart显示标记

    MPAndroidChart是实现图表功能的优秀控件, 能够完毕大多数绘制需求. 对于改动第三方库而言, 优秀的架构是继承开发, 而不是把源代码拆分出去. MP在显示标记控件(MarkView)时, ...

  7. node07---post请求、表单提交、文件上传

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. less02-变量

    html <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...

  9. javascript中如何获取对象名

    javascript中如何获取对象名 一.总结 一句话总结:将对象传入参数,看参数是否为函数(js中的对象和函数是一个意思么(函数肯定是对象)),对象参数.name属性即可获得 //版本4 funct ...

  10. thinkphp 中模型究竟是什么用?

    thinkphp 中模型究竟是什么用? 问题 似乎所有的操作都能在控制器中就能完成,模型除了几种验证之外,究竟是干什么用的,这个问题一直没理解透 解答 解答一 要明白这个问题,必须了解 MVC 历史. ...