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 ...
随机推荐
- 关于Http协议、ASP.NET 核心知识(2)
简介HTTP (对于http协议的描述我前部分有写,但基于保证文档独立完整性的原则,我再写一遍.反正又不花钱.) 这货的学名叫:超文本传输协议 英文名字:(HTTP,HyperText Transfe ...
- laravel前台html代码不显示
后天向前台传输变量,如果能取到变量数据,还有代码,但是不显示图片 可以把{{}}换成{!! !!}试试.
- C语言实现栈(顺序存储方式)
#include <stdio.h> #include <stdlib.h> //提供malloc()原型 #include <stdbool.h> //提供tru ...
- 2017ACM暑期多校联合训练 - Team 6 1008 HDU 6103 Kirinriki (模拟 尺取法)
题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B= ...
- spring-boot-资源处理
WebMvcConfigurerAdapter 使用 1.实现 HandlerInterceptorAdapter 2.添加拦截器 重写WebMvcConfigurerAdapter中的addInte ...
- 宋牧春: Linux设备树文件结构与解析深度分析(1) 【转】
转自:https://mp.weixin.qq.com/s/OX-aXd5MYlE_YoZ3p32qWA 作者简介 宋牧春,linux内核爱好者,喜欢阅读各种开源代码(uboot.linux.ucos ...
- memcached安装【转】
1.安装依赖软件 # yum -y install libevent libevent-devel perl-Test-Harness perl-Time-HiRes perl-TermReadKey ...
- Petrozavodsk Summer Training Camp 2017 Day 9
Petrozavodsk Summer Training Camp 2017 Day 9 Problem A. Building 题目描述:给出一棵树,在树上取出一条简单路径,使得该路径的最长上升子序 ...
- C++面试总结
1.多态 C++多态分两种--静态和动态,其中静态联编支持的多态称为编译时多态,包括重载和模板:动态联编支持的多态称为运行时多态,包括 继承和虚函数实现. 多态主要是由虚函数实现的,虚函数 ...
- springboot 零xml集成mybatis
maven依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...