题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2073

题解:跟风Xs酱!

数据范围这么小,肯定是状压DP。咦?怎么枚举子集?。。。

跪烂Xs:http://www.cnblogs.com/rausen/p/4263790.html

代码:

 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000+5
#define maxm 100000+5
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,mx,a[],b[],bin[],s[maxn],t[maxn],f[maxn];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
mx=read();n=read();
for1(i,n)a[i]=read(),b[i]=read();
bin[]=;
for1(i,n)bin[i]=bin[i-]<<;
for1(i,bin[n]-)for1(j,n)if(i&bin[j-])t[i]=max(t[i],a[j]),s[i]+=b[j];
memset(f,,sizeof(f));
f[]=;
for1(i,bin[n]-)
for(int j=i;j;j=i&(j-))
if(s[j]<=mx)f[i]=min(f[i],t[j]+f[i^j]);
cout<<f[bin[n]-]<<endl;
return ;
}

以后也用bin[i]表示1<<i吧,用一次写一次的话可能会出现各种奇怪的问题。。。

BZOJ2073: [POI2004]PRZ的更多相关文章

  1. 【BZOJ2073】[POI2004]PRZ 状压DP

    [BZOJ2073][POI2004]PRZ Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍 ...

  2. BZOJ 2073: [POI2004]PRZ( 状压dp )

    早上这道题没调完就去玩NOI网络同步赛了.... 状压dp , dp( s ) 表示 s 状态下所用的最短时间 , 转移就直接暴力枚举子集 . 可以先预处理出每个状态下的重量和时间的信息 . 复杂度是 ...

  3. 2073: [POI2004]PRZ

    2073: [POI2004]PRZ Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 284  Solved: 213[Submit][Status][D ...

  4. bzoj 2073: [POI2004]PRZ

    2073: [POI2004]PRZ Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的 ...

  5. Bzoj: 2073 [POI2004]PRZ 题解

    2073: [POI2004]PRZ Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 401  Solved: 296[Submit][Status][D ...

  6. 【bzoj2073】[POI2004]PRZ

    题目描述 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的人都不能超过一定的限制. 所以这只队伍过桥时只能分批 ...

  7. 【bzoj2073】[POI2004]PRZ 状态压缩dp

    题目描述 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的人都不能超过一定的限制. 所以这只队伍过桥时只能分批 ...

  8. 【bzoj2073】【[POI2004]PRZ】位运算枚举子集的特技

    (上不了p站我要死了) Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的人都不能超过一 ...

  9. BZOJ 2073: [POI2004]PRZ [DP 状压]

    传送门 水题不解释 这道题的主要目的在于记录一个枚举子集的技巧 #include <iostream> #include <cstdio> #include <cstri ...

随机推荐

  1. FACL的使用

    ACL的使用 ACL即Access Control List 主要的目的是提供传统的owner,group,others的read,write,execute权限之外的具体权限设置,ACL可以针对单一 ...

  2. c++ 函数返回指针 及用法

    #include<string> #include<iostream> using namespace std; string fun1(int a) { string str ...

  3. Spring3+hibernate4+struts2整合的 过程中发生如下错误

    严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...

  4. C# \uxxx Unicode编码解码

    /// <summary> /// Unicode编码 /// </summary> /// <param name="str"></pa ...

  5. uva 10330 最大流

    拆点  将节点 i 的容量拆成从 i 到 i+n 的边的容量 套用最大流模板 ac #include <cstdio> #include <cstdlib> #include ...

  6. What is the Best Programming Language to Learn in 2014?

    It’s been a year since I revealed the best languages to learn in 2013. Once again, I’ve examined the ...

  7. [转载]Spring Bean Definition Inheritance

    Following is the configuration file Beans.xml where we defined "helloWorld" bean which has ...

  8. Linked List vs Array

    Both Arrays and Linked List can be used to store linear data of similar types, but they both have so ...

  9. HDOJ 1856 More is better

    转自:wutianqi http://www.wutianqi.com/?p=1069 tag:并查集 #include <iostream> using namespace std; # ...

  10. POJ3083Children of the Candy Corn

    题意:给你一个迷宫,入口处标为S,出口处标为E,可以走的地方为“.”,不可以走的地方为#,求左转优先时从出口到入口的路程,再求右转优先时,出口到入口的路程,最后求从出口到入口的最短路程. 思路:求前两 ...