TCSRM 593 div2(1000)(dp)
Problem Statement |
|||||||||||||
| The pony Rainbow Dash wants to choose her pet. There are N animals who want to be her pet. Rainbow Dash numbered them 0 through N-1.
To For the race the Given two Rainbow |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Notes |
|||||||||||||
| - | The teams are not required to contain the same number of animals. | ||||||||||||
Constraints |
|||||||||||||
| - | A will contain between 2 and 50 elements, inclusive. | ||||||||||||
| - | A and B will contain the same number of elements. | ||||||||||||
| - | Each element of A will be between 1 and 10,000, inclusive. | ||||||||||||
| - | Each element of B will be between 1 and 10,000, inclusive. | ||||||||||||
| - | For each i, B[i] will be greater than or equal to A[i]. | ||||||||||||
Examples |
|||||||||||||
| 0) | |||||||||||||
|
|||||||||||||
| 1) | |||||||||||||
|
|||||||||||||
| 2) | |||||||||||||
|
|||||||||||||
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
木想出来
按和来进行背包 这样来看吧 如果按a数组来背 那我们要算出这几个值
s1(前面背出来的和值) s2(剩余的) a数组
s3(前面背出来的和值) s4(剩余的) b数组
想求s3-s2 和s1-s4 最值也就从这两种情况里取一个
如果按和背的话 直接就保存了 s1+s3 而(s2+s1)和(s3+s4)是定值 每次背的值 s1+s3-(s2+s1) 这样就出了s3-s2 同样s1-s4也求出来了
so easy...
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
using namespace std;
#define INF 0xfffffff
int dp[];
class MayTheBestPetWin
{
public:
int calc(vector <int> A, vector <int> B)
{
int n = A.size(),s1=,s2=,i,j;
for(i = ; i < n ; i++)
{
s1+=A[i];
s2+=B[i];
A[i]+=B[i];
}
int v = s1+s2;
memset(dp,,sizeof(dp));
dp[] = ;
for(i = ; i < n ; i++)
for(j = v ; j>=A[i] ; j--)
dp[j]=max(dp[j],dp[j-A[i]]);
int ans = INF;
for(i = ; i <= v ; i++)
{
if(dp[i]>)
{
ans = min(ans,max(abs(i-s1),abs(i-s2)));
}
}
return ans;
}
};
TCSRM 593 div2(1000)(dp)的更多相关文章
- Codeforces #426 Div2 D(线段树优化 DP )
#426 Div2 D 题意 给出 \(n\) 个数字,将这些数字隔成 \(k\) 个部分(相对位置不变),统计每个部分有几个不同数字,然后全部加起来求和,问和最大是多少. 分析 很容易想到 \(DP ...
- 洛谷3月月赛div2 题解(模拟+数学+贪心+数学)
由于本人太蒻了,div1的没有参加,胡乱写了写div2的代码就赶过来了. T1 苏联人 题目背景 题目名称是吸引你点进来的. 这是一道正常的题,和苏联没有任何关系. 题目描述 你在打 EE Round ...
- 【LeetCode】593. Valid Square 解题报告(Python)
[LeetCode]593. Valid Square 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地 ...
- CCPC-Wannafly Winter Camp Day8 (Div2, onsite) A 题 Aqours (精巧的树形DP)
题目链接: https://www.cometoj.com/contest/29/problem/A?problem_id=414 Aqours 题目描述 Aqours 正在 LoveLive! 决赛 ...
- Chrome开发者工具不完全指南:(三、性能篇)
卤煮在前面已经向大家介绍了Chrome开发者工具的一些功能面板,其中包括Elements.Network.Resources基础功能部分和Sources进阶功能部分,对于一般的网站项目来说,其实就是需 ...
- jquery笔记(仅供个人参考)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 2天驾驭DIV+CSS (实战篇)(转)
这是去年看到的一片文章,感觉在我的学习中,有不少的影响.于是把它分享给想很快了解css的兄弟们.本文是实战篇. 基础篇[知识一] “DIV+CSS” 的叫法是不准确的[知识二] “DIV+CSS” ...
- javascript 函数和作用域(闭包、作用域)(七)
一.闭包 JavaScript中允许嵌套函数,允许函数用作数据(可以把函数赋值给变量,存储在对象属性中,存储在数组元素中),并且使用词法作用域,这些因素相互交互,创造了惊人的,强大的闭包效果.[upd ...
- 集群之mysql主从配置(windows和linux版)
起因 由于网站进一步开发运行的需求,要求主机7*24小时运行正常,同时要求能够防止数据库灾难.考虑到后期的开发程度和业务量,准备向高可用系统进行改变,同时通过负载均衡提高网络性能.于是第一步就考虑到了 ...
随机推荐
- C语言基础:两个变量交换值的方法
学习任何语言基础时,两个数值得交换是必须掌握的,下面是3种不同的方式(c语言) 方法一:利用数学的计算技巧 #include <stdio.h> int main() { , b = ; ...
- js异步加载 defer和async 比较
网上说法很多,很少一句话能总结清楚的,终于找到两句一针见血的描述,很到位: 相同点:都不阻塞DOM解析 defer :顺序:保证先后顺序.解析:HTML 解析器遇到它们时,不阻塞(脚本将被异步下载) ...
- windows 64位整数
#include <iostream> #include <ctime> using namespace std; int main() { cout << cou ...
- Unity3D开发之“获取IOS设备所在的国家代码"
原地址:http://dong2008hong.blog.163.com/blog/static/469688272014021025578/ 在前一段时间游戏开发中需要实现获取IOS设备所在的国家代 ...
- 简单易懂的现代魔法——Play Framework攻略2
接前文:http://www.cnblogs.com/Kassadin/p/4335908.html 上次讲到Play Framework开发环境的配置,以及第一个Hello World程序:本次主要 ...
- Android ImageButton的背景(图片)大小
使用ImageButton的background属性,而不用src属性. 然后使用width和height进行调整.
- chmod命令详细用法
指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/Unix 的档案 ...
- 淘宝(taobao)HSF框架
一.背景 随着网站访问量增加,仅仅靠增加机器已不能满足系统的要求,于是需要对应用系统进行垂直拆分和水平拆分.在拆分之后,各个被拆分的模块如何通信?如何保证 性能?如何保证各个应用都以同样的方式交互?这 ...
- spring 与 CXF 整合 webservice 出现error “Unable to locate Spring NamespaceHandler for XML schema namespace” 总结
我试了多个版本的spring 发现 出现error : Unable to locate Spring NamespaceHandler for XML schema namespace 并非都是sp ...
- Web中的监听器【Listener】
Servlet监听器:Servlet规范中定义的一种特殊类,它用于监听Web应用程序中的ServletContext.HttpSession和ServletRequest等域对象的创建与销毁事件,以及 ...