cf 730J. Bottles
搞一个背包,233
要求用的瓶数最少,那么就业瓶数为第一关键,当瓶数相当后再以a[i]
#include<bits/stdc++.h>
#define N 100005
#define LL long long
#define inf 0x3f3f3f3f
#define ls tr[x][0]
#define rs tr[x][1]
using namespace std;
inline int ra()
{
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 a[N],b[N];
int f[N],size[N];
int main()
{
int n=ra(),sum=,tot=;
memset(size,0x7,sizeof(size)); size[]=;
for (int i=; i<=n; i++) a[i]=ra(),sum+=a[i];
for (int i=; i<=n; i++) b[i]=ra(),tot+=b[i];
for (int i=; i<=n; i++)
for (int j=tot; j>=; j--)
{
if (size[j]+==size[j+b[i]])
f[j+b[i]]=max(f[j+b[i]],f[j]+a[i]);
if (size[j]+<size[j+b[i]])
{
size[j+b[i]]=size[j]+;
f[j+b[i]]=f[j]+a[i];
}
}
int anssz=inf,ans;
for (int i=sum; i<=tot; i++)
{
if (anssz==size[i])
ans=max(ans,f[i]);
if (anssz>size[i])
{
anssz=size[i];
ans=f[i];
}
}
printf("%d %d",anssz,sum-ans);
return ;
}
大为第二关键(因为要求转移时间最小,我们选出的是不转移的瓶子,所以要求最大)
cf 730J. Bottles的更多相关文章
- 4.8cf自训
发现cf以前的好题真的很多.. cf 730j 01背包变形 感觉很好的题 /* 先处理出最少需要t个瓶子 dp[i][j][k]前i个取k个,容量为j时的水的体积 滚动数组搞一下 本题的状态转移必须 ...
- CF 672C Recycling Bottles[最优次优 贪心]
C. Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 730J:Bottles(背包dp)
http://codeforces.com/problemset/problem/730/J 题意:有n个瓶子,每个瓶子有一个当前里面的水量,还有一个瓶子容量,问要把所有的当前水量放到尽量少的瓶子里至 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- Codeforces CF#628 Education 8 A. Tennis Tournament
A. Tennis Tournament time limit per test 1 second memory limit per test 256 megabytes input standard ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
随机推荐
- Docker 镜像文件的导入和导出
使用save命令 保存镜像 docker save -o name_by_you.tar exist_images 将文件copy到另一台机器 使用load命令将镜像文件保存到本地仓库 docker ...
- C++服务器与java进行socket通信案例
分类: [java]2012-10-08 12:03 14539人阅读 评论(46) 收藏 举报 注:本代码版权所有!!!转载时请声明源地址:http://blog.csdn.net/nuptboyz ...
- LoadRunner回放脚本时,显示浏览器的设置
打开LoadRunner的VuGen,选择Tools-->General Options-->Display,在Display里将 Show browser during replay打钩 ...
- firewalld学习--service
service是firewalld中另外一个非常重要的概念.还是拿门卫的例子来解释. 在iptables的时代我们给门卫下达规则时需要告诉他“所有到22号楼的人全部予以放行”.“所有到80号楼的人全部 ...
- SCHema学习
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http:/ ...
- spark aggregate算子
spark aggregate源代码 /** * Aggregate the elements of each partition, and then the results for all the ...
- 二、Vue组件(component):组件的相互引用、通过props实现父子组件互传值
一.组件各部分说明及互相引用 1.一个vue组件由三个部分组成 Template 只能存在一个根元素 2.Script 3.Style scoped:样式只在当前组件内生效 1.1 组件的基本引用代码 ...
- Spring入门之三-------SpringIoC之Scopes
一.singleton和prototype public class Bean1 { public Bean1() { System.out.println(this.getClass().getSi ...
- Percona-Toolkit 之 pt-archiver 删除历史数据
pt-archiver是Percona-Toolkit工具集中的一个组件,是一个主要用于对MySQL表数据进行归档和清除工具.它可以将数据归档到另一张表或者是一个文件中.pt-archiver在清除表 ...
- spring boot 使用swagger
在pom.xml中添加maven依赖 <dependency> <groupId>io.springfox</groupId> <artifactId> ...