[DP] BZOJ 4247 挂饰
来源:互联网 发布:枫树浏览器 知乎 编辑:程序博客网 时间:2024/06/10 03:34
一个01背包
#include<cstdio>#include<cstdlib>#include<algorithm>#include<functional>#include<cstring>using namespace std;typedef pair<int,int> abcd;inline char nc(){static char buf[100000],*p1=buf,*p2=buf;if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); return EOF; }return *p1++;}inline void read(int &x){char c=nc(),b=1;for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}int n,ans; abcd s[2500];int f[2][2500]; int main() {int t;freopen("t.in","r",stdin);freopen("t.out","w",stdout);read(n);for(int i=1;i<=n;i++) read(s[i].first),read(s[i].second);sort(s+1,s+n+1,greater<abcd>());memset(f,-0x3f,sizeof(f));f[t=0][1]=0;for(int i=1;i<=n;i++,t^=1)for(int j=0;j<=n;j++) f[t^1][j]=max(f[t][j-s[i].first+1>1?j-s[i].first+1:1]+s[i].second,f[t][j]); for(int i=0;i<=n;i++) ans=max(ans,f[t][i]); printf("%d\n",ans); return 0;}
0 0
- [DP] BZOJ 4247 挂饰
- BZOJ 4247: 挂饰 背包dp
- bzoj 4247: 挂饰 背包dp
- bzoj 4247: 挂饰(DP)
- bzoj 3864 dp套dp
- BZOJ 1087 状压DP
- BZOJ 1207 DP
- BZOJ 2152 (树形DP)
- BZOJ 3791 作业 DP
- BZOJ 4352 预处理 + DP
- bzoj 3037(树形DP)
- bzoj 1003(spfa+dp)
- BZOJ 1003 SPFA + DP
- bzoj 4027 树形dp
- bzoj 3573(树形DP)
- bzoj 1021 dp
- bzoj 4347 dp
- bzoj 4380 dp
- Java进阶(三)多线程开发关键技术
- ZooKeeper 安装部署及hello world
- python简单之isinstance,type使用
- sublime编辑器【快捷键】基本用法,sublime小技巧
- [leetcode]Single Number
- [DP] BZOJ 4247 挂饰
- [转]两种高性能I/O设计模式(Reactor/Proactor)的比较
- 一步步追踪Dialog的创建流程(一)
- Servlet的生命周期分为3个阶段:? 和CGI的区别
- Jimoshi_整合三大框架(二)--添加用户信息数据、删除用户信息数据、修改用户信息数据
- 1NF 2NF 3NF BCNF
- git命令小结
- python dictionary
- JDK环境变量的配置