TC SRM 593 DIV2 1000
很棒的DP,不过没想出,看题解了。。思维很重要。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int dp[];
int sum[];
class MayTheBestPetWin
{
public :
int calc(vector <int> A, vector <int> B)
{
int i,j,s1,s2;
s1 = s2 = ;
memset(dp,-,sizeof(dp));
dp[] = ;
for(i = ;i < A.size();i ++)
{
sum[i] = A[i] + B[i];
}
for(i = ;i < A.size();i ++)
{
s1 += A[i];
s2 += B[i];
for(j = ;j >= sum[i];j --)
{
if(dp[j-sum[i]] != -&&dp[j] <= dp[j-sum[i]] + sum[i])
{
dp[j] = dp[j-sum[i]] + sum[i];
}
} }
int minz = ,t1,t2;
for(i = ;i <= ;i ++)
{
if(dp[i] != -)
{
t1 = abs(s1-i);
t2 = abs(s2-i);
minz = min(minz,max(t1,t2));
}
}
return minz;
}
};
TC SRM 593 DIV2 1000的更多相关文章
- TC SRM 591 DIV2 1000
很不错的一题,非常巧妙的用DP顺序解决这个问题... 可以发现,只和A里面最小的有关系... #include <cstdio> #include <cstring> #inc ...
- Topcoder Srm 673 Div2 1000 BearPermutations2
\(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...
- Topcoder Srm 671 Div2 1000 BearDestroysDiv2
\(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...
- TC SRM 663 div2 B AABB 逆推
AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...
- SRM 595 DIV2 1000
数位DP的感觉,但是跟模版不是一个套路的,看的题解,代码好理解,但是确实难想. #include <cstdio> #include <cstring> #include &l ...
- TC SRM 663 div2 A ChessFloor 暴力
ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...
- TC SRM 665 DIV2 A LuckyXor 暴力
LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive int ...
- SRM 146 DIV2 1000
Problem Statement A well-known riddle goes like this: Four people are crossing an old bridge. T ...
- TC SRM 593 DIV1 250
我只能说的亏没做,要不就挂0了.. 本来想四色定理,肯定4就可以的...然后准备爆,发现3的时候不好爆,又想了老一会,嗯,数据范围不小,应该不是暴力,直接找规律,貌似最大就是3,有一个3连块,输出3, ...
随机推荐
- Bootstrap简介
接下来的一段时间,想研究一下现有的网页框架,第一个不容错过的就是Bootstrap,Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架.Bootstrap 是基于 HTML.CS ...
- 【翻译二】java--并发之进程与线程
Processes and Threads In concurrent programming, there are two basic units of execution: processes a ...
- 【leetcode】Sqrt(x)
题目描述: Implement int sqrt(int x). Compute and return the square root of x. 实现开根号,并且返回整数值(这个很重要,不是整数的话 ...
- js中ascii码的转换
今天在把原来用C写的程序移植到javascript上,但是有个地方一直调不通,后来才发现是js奇葩的字符处理出的问题.c中使用的字符处理比如加上一个字符值强制转换一下,在js中就行不通了. 但是js提 ...
- JDK 1.5 1.6 override区别
今天在更新时发现有个别项目报错,报错信息 到网上搜索了之后,根据网上描述,修改了一批配置都不行: http://bestchenwu.iteye.com/blog/997420(这个里面的方法二,即为 ...
- ASSM 的三级位图结构
自动段空间管理(ASSM),它首次出现在Oracle920里(在920以前,段空间的管理方式叫做MSSM,它是由连接列表freelist来完成的,因为freelist存在串行的问题,因此容易引起段头的 ...
- list[C++]
//双向链表 #include <iostream> using namespace std; #include <list> int main(int argc, const ...
- tcflush 功能(转)
tcflush() 丢弃要写入引用的对象,但是尚未传输的数据,或者收到但是尚未读取的数据,取决于 queue_selector 的值: TCIFLUSH 刷新收到的数据但是不读 TCOFLUSH 刷新 ...
- 类模板Queue的实现
#include <iostream> #include <vector> using namespace std; template <class Type> c ...
- ios 音乐播放
#import "ViewController.h" #import <AVFoundation/AVFoundation.h> @interface ViewCont ...