poj 1678 I Love this Game!
思路:这题和博弈论的关系不大,主要是DP。记忆化搜索即可!!!
取的数一定是大于0的,所以将负数去掉!!
代码如下:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#define inf 1e9
using namespace std;
int dp[],n,a[],l,r;
int dfs(int m)
{
if(dp[m]!=inf) return dp[m];
int ans=inf;
for(int i=m+;i<n;i++){
if(a[i]-a[m]>=l&&a[i]-a[m]<=r)
ans=min(ans,a[m]-dfs(i));
}
if(ans==inf) return dp[m]=a[m];
return dp[m]=ans;
}
int solve()
{
int ans=-inf;
for(int i=;i<n;i++){
if(a[i]>=l&&a[i]<=r)
ans=max(ans,dfs(i));
}
return ans==-inf?:ans;
}
int main()
{
int i,j,q,k,t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&l,&r);
for(i=j=;i<n;i++){
scanf("%d",&q);
if(q>) a[j++]=q;
dp[i]=inf;
}
n=j;
sort(a,a+n);
printf("%d\n",solve());
}
return ;
}
poj 1678 I Love this Game!的更多相关文章
- 博弈dp入门 POJ - 1678 HDU - 4597
本来博弈还没怎么搞懂,又和dp搞上了,哇,这真是冰火两重天,爽哉妙哉. 我自己的理解就是,博弈dp有点像对抗搜索的意思,但并不是对抗搜索,因为它是像博弈一样,大多数以当前的操作者来dp,光想是想不通的 ...
- POJ 1678 I Love this Game!#dp博弈
http://poj.org/problem?id=1678 #include<iostream> #include<cstdio> #include<cstring&g ...
- 博弈dp 以I Love this Game! POJ - 1678 为例
写在前面的话 知识基础:一些基础的博弈论的方法,动态规划的一些知识 前言:博弈论就是一些关于策略或者游戏之间的最优解,动态规划就是对于一些状态之间转移的一些递推式(or 递归),dp分为很多很多种,比 ...
- POJ 1678
博弈题,使用DP来完成.开始时,我以为可以用极大极小加剪枝可以过,但,TLE... 看过一些题解,没看懂,但也由此有了启发: 我们只记录差(初始为0),那为1选的数即为在原差值上加上该数,2选即是减去 ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 转载:poj题目分类(侵删)
转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) ...
- poj 3714 Raid【(暴力+剪枝) || (分治法+剪枝)】
题目: http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#prob ...
随机推荐
- hdu 1509 Windows Message Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...
- [译]rabbitmq 2.1 Consumers and producers (not an economics lesson)
我对rabbitmq学习还不深入,这些翻译仅仅做资料保存,希望不要误导大家. For now, all you need to know is that producers create messag ...
- linux下操作
一.没有正确安装GNOME电源管理器的默认配置 二.oracle启停 1. linux下启动oraclesu - oraclesqlplus /nologconn /as sysdbastartupe ...
- Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案
#Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案 ##问题描述 使用Python2.7.x运行GAE时有时会报这个错误 ```py ...
- ALTERA MAX10官方评估板,新鲜出炉!
刚刚拿到骏龙提供的ALTERA MAX10官方评估板,还热乎呢,呵呵!赶紧跟大家分享一下 板子很简单,把IO口都扩展出来了,其他功能基本上没有. FPGA型号是10M08SAE144C8GES,144 ...
- [SSH服务]——SSH端口转发
实验拓扑图 实验描述 假设有三台主机A.B.C.B和A.C可以连通,AC两台主机不能连通. 这时候可以用本地端口转发,来实现A和C通过B来连通. 实验中,为了构造上述环境,我们使用三台虚拟机,其网络环 ...
- online training
https://www.skillfeed.com/browse http://teamtreehouse.com/features http://www.pluralsight.com/ https ...
- How to check if NSString begins with a certain character
How to check if NSString begins with a certain character How do you check if an NSString begins with ...
- 文件操作的openmode
C中文件的openmode如下: r 只读 为输入打开一个文本文件 w 只写 为输出打开一个文本文件 a 追加 向文本文件尾添加数据 rb 只读 为输入打开一个二进制文件 wb 只写 为输出打开一个二 ...
- VS(C++)编程遇到的错误集合
编译错误 1.error C1010: 原因:没有在文件开头添加include "stdafx.h". 2.error C2440: "=": 无法从" ...