p1315构建双塔 dp
|
||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int a[]={};
int f[][]={};
int sum[]={};
int sumn=;
int main(){
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i];
sumn+=a[i];
sum[i]=sumn;
}
for(int i=;i<=sumn;i++){
f[][i]=-;
}
f[][]=;
for(int i=;i<=n;i++){
for(int j=;j<=sumn;j++){
f[i][j]=f[i-][j];
if(j>=a[i]&&f[i-][j-a[i]]>-){
f[i][j]=max(f[i][j],f[i-][j-a[i]]);
}
if(a[i]>j&&f[i-][a[i]-j]>-){
f[i][j]=max(f[i][j],f[i-][a[i]-j]+a[i]-j);
}
if(j+a[i]<=sumn&&f[i-][a[i]+j]>-){
f[i][j]=max(f[i][j],f[i-][a[i]+j]+a[i]);
}
}
}
if(f[n][]>){
cout<<f[n][]<<endl;
}
else{
cout<<"Impossible"<<endl;
}
return ;
}
p1315构建双塔 dp的更多相关文章
- ZOJ2401 Zipper 双塔式 DP(双塔DP)
第二次遇到双塔DP,再写一下. (flag是为了避免memset多次导致的时间浪费) #include<cstdio> #include<cstdlib> #include&l ...
- HDU 3578 Greedy Tino(双塔DP)
Greedy Tino Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- POJ 2609 Ferry Loading(双塔DP)
Ferry Loading Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1807 Accepted: 509 Sp ...
- ZOJ 3331 Process the Tasks(双塔DP)
Process the Tasks Time Limit: 1 Second Memory Limit: 32768 KB There are two machines A and B. T ...
- ZOJ 2059 The Twin Towers(双塔DP)
The Twin Towers Time Limit: 2 Seconds Memory Limit: 65536 KB Twin towers we see you standing ta ...
- VIJOS P1037搭建双塔[DP]
描述 2001年9月11日,一场突发的灾难将纽约世界贸易中心大厦夷为平地,Mr. F曾亲眼目睹了这次灾难.为了纪念“9?11”事件,Mr. F决定自己用水晶来搭建一座双塔. Mr. F有N块水晶,每块 ...
- 【P1351】构建双塔
奇怪的DP 原题: 2001年9月11日,一场突发的灾难将纽约世界贸易中心大厦夷为平地,Mr. F曾亲眼目睹了这次灾难.为了纪念“9?11”事件,Mr. F决定自己用水晶来搭建一座双塔. Mr. F有 ...
- ZOJ 3331 Process the Tasks 双塔Dp
用dp[i][j]表示当前安排好了前i个任务,且机器A和机器B完成当前分配到的所有任务的时间差为j(这里j可正可负,实现的时候需要加个offset)时,完成这些任务的最早时间.然后根据j的正负,分别考 ...
- POJ 1015 Jury Compromise(双塔dp)
Jury Compromise Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33737 Accepted: 9109 ...
随机推荐
- 2017ACM暑期多校联合训练 - Team 8 1011 HDU 6143 Killer Names (容斥+排列组合,dp+整数快速幂)
题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith ...
- HDU 1256 画8 (找规律)
题目链接 Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中 ...
- ThinkPHP的运行流程-2
Thinkphp为了提高编译的效率,第一次运行的时候thinkphp会把文件全部编译到temp目录下的~runtime.php文件,在第二次运行的时候会直接读取这个文件.所以我们在线下自己写代码测试的 ...
- PIP安装时报The repository located at pypi.douban.com is not a trusted or secure host and is being ignore
C:\WINDOWS\system32>pip install scrapyCollecting scrapy The repository located at pypi.douban.com ...
- juery中循环遍历json数组
var dataList=[]; var stock0={stockcode:"007758",stockname:"商业政7",state:"1&q ...
- python的sorted函数对字典按value进行排序
场景:词频统计时候,我们往往要对频率进行排序 sorted(iterable,key,reverse),sorted一共有iterable,key,reverse这三个参数.其中iterable表示可 ...
- Jmeter------将JDBC Request的查询结果作为另一个接口的请求参数
一.前言 jmeter已配置连接成功数据库,不会的可查看:https://www.cnblogs.com/syw20170419/p/9832402.html 二.需求 将JDBC Request的r ...
- 783. Minimum Distance Between BST Nodes
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...
- Nuxt 2.0 需要将pug-loader改成pug-plain-loader
Nuxt 2.0 需要将pug-loader改成pug-plain-loader npm i pug-plain-loader -D 解决问题!! 参考链接 https://my.oschina.ne ...
- 某PCBA企业应用易普优APS实现高级计划排程案例
一.项目介绍 1.生产计划现状 某PCBA企业(以下简称A企业)的产品生产是典型的多品种.小批量.多变化的生产模式.其中产品种类有1000多种,主流的200多种,每个月数百个生产订单,分解到工序以后的 ...