poj 2287 动态规划
用贪心简单证明之后就是一个从两头取的动态规划
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=1e3+9;
int a[maxn],b[maxn];
int dp[maxn][maxn]; bool cmp(int a,int b)
{
return a>b;
} int main()
{
int n;
while(scanf("%d",&n),n)
{
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
sort(a+1,a+1+n,cmp);
sort(b+1,b+1+n,cmp);
memset(dp,200,sizeof(dp));
dp[0][0]=0;
for(int i=0;i<=n;i++)
for(int j=0;j+i<n;j++)
{
if(a[i+1]>b[i+j+1])
dp[i+1][j]=max(dp[i+1][j],dp[i][j]+200);
else if(a[i+1]<b[i+j+1])
dp[i+1][j]=max(dp[i+1][j],dp[i][j]-200);
else
dp[i+1][j]=max(dp[i+1][j],dp[i][j]); if(a[n-j]>b[i+j+1])
dp[i][j+1]=max(dp[i][j+1],dp[i][j]+200);
else if(a[n-j]<b[i+j+1])
dp[i][j+1]=max(dp[i][j+1],dp[i][j]-200);
else
dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
}
int ans=-1e7;
for(int i=0;i<=n;i++)
ans=max(ans,dp[i][n-i]);
cout<<ans<<endl;
}
return 0;
}
poj 2287 动态规划的更多相关文章
- nyoj 17-单调递增最长子序列 && poj 2533(动态规划,演算法)
17-单调递增最长子序列 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:21 submit:49 题目描述: 求一个字符串的最长递增子序列的长度 如 ...
- poj 3034 动态规划
思路:这是一道坑爹的动态规划,思路很容易想到,就是细节. 用dp[t][i][j],表示在第t时间,锤子停在(i,j)位置能获得的最大数量.那么只要找到一个点转移到(i,j)收益最大即可. #incl ...
- poj 2498 动态规划
思路:简单动态规划 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...
- poj 2287(贪心)
Tian Ji -- The Horse Racing Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 12490 Acc ...
- POJ 2533 动态规划入门 (LIS)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42914 Accepte ...
- poj 1821 动态规划
思路:每次枚举每个工人的右边界j,维护最优的左边界k.那么dp[j]=max(dp[j],dp[k]+(j-k)*w[i].p): 对于每个工人的初值k=w[i].s-1; 令x=j-w[i].l,如 ...
- poj 1390 动态规划
思路: 黑书的例题 #include<iostream> #include<cstring> #include<algorithm> #include<cma ...
- poj 1695 动态规划
思路:和黑书上的跳舞机类似 #include<map> #include<set> #include<cmath> #include<queue> #i ...
- poj 1141 动态规划进行括号匹配
思路:黑书的例题 #include<iostream> #include<cstring> #include<cstdio> #include<algorit ...
随机推荐
- Oracle sqlplus 语法
目录: 0. FREFACE 1. 执行一个SQL脚本文件 2. 对当前的输入进行编辑 3. 重新运行上一次运行的sql语句 4. 将显示的内容输出到指定文件 5. 关闭spool输出 6.显示一个表 ...
- requirejs2读书笔记
If you want to do require() calls in the HTML page, then it is best to not use data-main. data-main ...
- 新版福昕阅读器(Foxit Reader)启动速度慢解决办法
新版福昕阅读器(FoxitReader)启动速度慢解决办法之前喜欢使用福昕阅读器的原因就是看中了其小巧,可是最近版本的阅读器打开速度变得慢了很多(不是电脑配置问题),比AdobeReader还要慢,这 ...
- [RxJS] Returning subscriptions from the subscribe function
So far, when writing these subscribe functions, we haven't returned anything. It is possible return ...
- [RxJS] Creation operators: interval and timer
It is quite common to need an Observable that ticks periodically, for instance every second or every ...
- JAVA - Comparable接口 与 Comparator接口
Similarities:Both are custom ways to compare two objects.Both return an int describing the relatio ...
- hdu 2544
#include <iostream> #include <cstdio> #define INF 9999999 //#define INF 0x3f3f3f3 using ...
- Android开发手记(8) ProgressDialog的使用
ProgressDialog,进度对话框.一般有两种,一种是圆形的进度条(ProgressDialog.STYLE_SPINNER),另一种是长条形的进度条(ProgressDialog.STYLE_ ...
- MSSQL 查询统计某状态出现的次数及累计时间
1.问题来源 最近客户需要统计某个设备,某状态,在某一个时间段内出现的次数,并计算累计出现的时间. 数据源如下: 现在如果要统计UPSCTSTA状态为D出现的次数(同一状态,连续出现的认为是一次),并 ...
- CSS块级元素与行级元素(转载)
块元素一般都从新行开始,它可以容纳内联元素和其他块元素,常见块元素是段落标签'P".“form"这个块元素比较特殊,它只能用来容纳其他块元素. 如果没有css的作用,块元素会顺序以 ...