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. 服务器启用 FTP

    通常使用 vsftpd 作为FTP服务器. 安装 vsftpd: 1.以管理员(root)身份执行以下命令 yum install vsftpd 2.设置开机启动 vsftpd ftp 服务 chkc ...

  2. Java——日期格式

     /* * 日期对象和毫秒值之间的转换. * * 毫秒值--->日期对象: *  1.通过Date对象的构造方法new Date(timeMillis) *  2.还可以通过setTime设 ...

  3. A Gentle Introduction to the Gradient Boosting Algorithm for Machine Learning

    A Gentle Introduction to the Gradient Boosting Algorithm for Machine Learning by Jason Brownlee on S ...

  4. CUDA编程

    目录: 1.什么是CUDA 2.为什么要用到CUDA 3.CUDA环境搭建 4.第一个CUDA程序 5. CUDA编程 5.1. 基本概念 5.2. 线程层次结构 5.3. 存储器层次结构 5.4. ...

  5. Agent admitted failure to sign using the key

    SSH生成id_rsa, id_rsa.pub后,连接服务器却报: Agent admitted failure to sign using the key 错误. 解决方法: 在当前用户下执行命令: ...

  6. android语言适配

    虽然我们现在做的app基本只在国内使用,所以只需要中文,但是我们要把眼光放长远一点,以后我们的APP发展到了国外呢,所以我们就要做语言适配了   很简单 在res目录下,右键  New Resourc ...

  7. IIS调用COM组件的权限问题

    在DCOM组件服务中给MICROSOFT.EXCEL组件 赋予ASP.NET的操作权限,具体步骤: (1)打开开始菜单的运行对话框,输入dcomcnfg命令,确定,这时会弹出组件服务窗口 (2)展开计 ...

  8. 使用Ef时,对一个或多个实体的验证失败。有关详细信息,请参见“EntityValidationErrors”属性。

    EntityValidationErrors   关于如何查看 EntityValidationErrors 详细信息的解决方法 我们在 EF 的编程中,有时候会遇到这样一个错误: 但是,按照他的提示 ...

  9. x2go

    单词解析    productivity    n. 生产力:生产率:生产能力seamlessly    adv. 无缝地roam constantly    经常漫游agility and flex ...

  10. noip2003复赛普及组第一题——乒乓球

    /*======================================================================= 题一.乒乓球(Table.pas) [问题背景]国际 ...