1.将一堆正整数分为2组,要求2组的和相差最小。

  //File Name: nod1007.cpp
//Author: long
//Mail: 736726758@qq.com
//Created Time: 2016年05月28日 星期六 20时12分23秒 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream> using namespace std; bool f[][];
int a[]; void solve(int n){
memset(f,false,sizeof f);
f[][] = true;
int now = ;
for(int i=;i<=n;i++){
now += a[i];
for(int j=;j<=now;j++){
f[i][j] = f[i-][j];
if(j >= a[i]) f[i][j] |= f[i-][j-a[i]];
}
}
int ans = ;
for(int i=;i<=now;i++){
if(!f[n][i]) continue;
ans = min(ans,abs(now - * i));
}
printf("%d\n",ans);
} int main(){
int n;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
solve(n);
}
return ;
}

2.最长递增子序列

  //File Name: nod1134.cpp
//Author: long
//Mail: 736726758@qq.com
//Created Time: 2016年05月28日 星期六 20时45分45秒 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream> using namespace std; const int MAXN = + ;
const int INF = 0x3f3f3f3f; int d[MAXN];
int a[MAXN]; int bs(int l,int r,int x){
int mid;
while(r - l > ){
mid = (l + r) >> ;
if(d[mid] < x) l = mid;
else r = mid;
}
return l;
} int solve(int n){
int len = ;
d[] = -INF;
for(int i=,j;i<=n;i++){
if(a[i] > d[len]){
d[++len] = a[i];
}
j = bs(,len,a[i]);
d[++j] = a[i];
}
return len;
} int main(){
int n;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
printf("%d\n",solve(n));
}
return ;
}

3.最大子矩阵和

一个M*N的矩阵,找到此矩阵的一个子矩阵,并且这个子矩阵的元素的和是最大的,输出这个最大的值

  //File Name: nod1051.cpp
//Author: long
//Mail: 736726758@qq.com
//Created Time: 2016年05月28日 星期六 21时22分03秒 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream> #define LL long long using namespace std; const int MAXN = ; LL b[MAXN],f[MAXN];
int a[MAXN][MAXN]; LL get(int n){
LL ans = ;
f[] = ;
for(int i=;i<=n;i++){
f[i] = max(f[i-],0LL) + b[i];
if(f[i] > ans) ans = f[i];
}
return ans;
} LL solve(int n,int m){
LL ans = -;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++) b[j] = ;
for(int j=i;j<=n;j++){
for(int k=;k<=m;k++)
b[k] = b[k] + a[j][k];
LL now = get(m);
if(now > ans) ans = now;
}
}
return ans;
} int main(){
int n,m;
while(~scanf("%d %d",&m,&n)){
bool flag = false;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&a[i][j]);
if(a[i][j] >= ) flag = true;
}
}
if(!flag) puts("");
else printf("%lld\n",solve(n,m));
}
return ;
}

easy dp的更多相关文章

  1. BZOJ 3450: Tyvj1952 Easy [DP 概率]

    传送门 题意:$ox?$组成的序列,$?$等概率为$o\ or\ x$,得分为连续的$o$的长度的平方和,求期望得分 一开始没想出来,原因在于不知道如何记录长度 其实我们同时求得分和长度的期望就好了 ...

  2. 【dp入门题】【跟着14练dp吧...囧】

    A HDU_2048 数塔 dp入门题——数塔问题:求路径的最大和: 状态方程: dp[i][j] = max(dp[i+1][j], dp[i+1][j+1])+a[i][j];dp[n][j] = ...

  3. Code Forces 698A Vacations

    题目描述 Vasya has nn days of vacations! So he decided to improve his IT skills and do sport. Vasya know ...

  4. EOJ Monthly 2018.2

    A. 坑爹的售票机 题意 用\(1,5,10,25,50,100\)的纸币买\(n\)张单价为\(p\)的船票,且一次性最多买\(k\)张,求钱数恰好时最少需要多少张纸币. Hard: \(n,k,p ...

  5. EOJ Monthly 2018.1 F 最小OR路径

    题目链接 Description 给定一个有 \(n\) 个点和 \(m\) 条边的无向图,其中每一条边 \(e_i\) 都有一个权值记为 \(w_i\) . 对于给出的两个点 \(a\) 和 \(b ...

  6. ZOJ3802 Easy 2048 Again (状压DP)

    ZOJ Monthly, August 2014 E题 ZOJ月赛 2014年8月 E题 http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  7. Easy 2048 Again - ZOJ 3802 像缩进dp

    Easy 2048 Again Time Limit: 2 Seconds      Memory Limit: 65536 KB Dark_sun knows that on a single-tr ...

  8. Codeforces 1077F1 Pictures with Kittens (easy version)(DP)

    题目链接:Pictures with Kittens (easy version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:$dp[i][j ...

  9. CF1096:D. Easy Problem(DP)

    Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement ...

随机推荐

  1. POJ1419 Graph Coloring(最大独立集)(最大团)

                                                               Graph Coloring Time Limit: 1000MS   Memor ...

  2. Python字符串分割

    代码如下: [root@localhost test]# cat 3.py #coding=utf-8 ev = """ 1evilxr 2www 3nihao 4evi ...

  3. Awesome Reinforcement Learning

    Awesome Reinforcement Learning A curated list of resources dedicated to reinforcement learning. We h ...

  4. .NET GC Server-Background-GC

    Garbage Collection and Performancehttps://msdn.microsoft.com/en-us/library/ee851764(v=vs.110).aspx h ...

  5. Unity3D的杂记

    刷新帧的不同控制函数 FixedUpdate 可以多次调用: 不饿能用于帧频很高的情况: Update 仅一次调用(每帧): LateUpdate 每帧调用一次: Corountine 用startC ...

  6. 通过JavaScript更新UpdatePanel备忘

    1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs ...

  7. ABBYY FineReader的快速任务功能如何用

    在使用ABBYY FineReader Pro for Mac OCR文字识别软件处理文档时,经常会执行一系列相同的步骤,如扫描.识别.将已识别文本导出为特定格式或导出至特定应用程序.针对经常执行的任 ...

  8. OpenJudge计算概论-计算三角形面积【海伦公式】

    /*============================================== 计算三角形面积 总时间限制: 1000ms 内存限制: 65536kB 描述 平面上有一个三角形,它的 ...

  9. 运用cookie登陆人人网爬取数据

    浏览器访问WEB服务器的过程 在用户访问网页时,不论是通过URL输入域名或IP,还是点击链接,浏览器向WEB服务器发出了一个HTTP请求(Http Request),WEB服务器接收到客户端浏览器的请 ...

  10. [Android设计模式]Android退出应用程序终极方法

    如何干净彻底地退出Android应用程序,是很多开发者的心头痒.如何干净地关闭所有已打开的Activity? 如何关闭指定的Activity? 如何关闭一类Activity? 这里,我们提出一种通过实 ...