http://www.lightoj.com/volume_showproblem.php?problem=1017

题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个。

思路:状态设计DP[i][j]代表刷子下边界为i已用了j次时最大个数。决策为扫和跳过。

/** @Date    : 2016-12-18 14:25:51
* @FileName: LightOJ 1017 DP?.cpp
* @Platform: Windows
* @Author : Lweleth (SoundEarlf@gmail.com)
* @Link : https://github.com/Lweleth
* @Version : $Id$
*/
// #include <stdio.h>
// #include <iostream>
// #include <string.h>
// #include <algorithm>
// #include <utility>
// #include <vector>
// #include <map>
// #include <set>
// #include <string>
// #include <stack>
// #include <queue>
#include<bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; int y[110];
int dp[110][110]; int n, w, k;
int ref(int s, int k)
{
if(s >= n || k < 1)
return 0;
if(dp[s][k] != -1)
return dp[s][k];
int sp, sk;
int cnt = 0;
int i;//考虑有负数的情况
for(i = s; i < n; i++)
{
if(y[i] - y[s] <= w)
cnt = i - s + 1;
else break;
}
sp = cnt + ref(i, k - 1);//选择扫
sk = ref(s + 1, k);//跳过 dp[s][k] = max(sp, sk);
return dp[s][k];
} int main()
{ int T;
int cnt = 0;
cin >> T;
while(T--)
{
scanf("%d%d%d", &n, &w, &k);
for(int i = 0; i < n; i++)
{
int x;
scanf("%d%d", &x, y + i);
}
sort(y, y + n);
MMG(dp);
int ans = ref(0, k);
printf("Case %d: %d\n", ++cnt, ans);
}
return 0;
}

LightOJ 1017 - Brush (III) 记忆化搜索+细节的更多相关文章

  1. Lightoj 1017 - Brush (III)

    1017 - Brush (III)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sam ...

  2. lightOJ 1017 Brush (III) DP

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...

  3. HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...

  4. lightoj 1283 - Shelving Books(记忆化搜索+区间dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1283 题解:这题很显然一看就像是区间dp,但是单纯的区间dp好像解决不了问题可 ...

  5. LA 6042 Bee Tower 记忆化搜索

    一开始读漏了很多细节,用递推写死活跑不出样例. 把题目中的细节列一下吧,状态方程很好推,改成记忆化搜索之后代码也很清晰. 1.蜜蜂需要到最高的塔去,最高的塔可能不止一个,抵达任意一个即可. 2.蜜蜂每 ...

  6. Codevs_1017_乘积最大_(划分型动态规划/记忆化搜索)

    描述 http://codevs.cn/problem/1017/ 给出一个n位数,在数字中间添加k个乘号,使得最终的乘积最大. 1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提 ...

  7. 8636 跳格子(dfs+记忆化搜索)

    8636 跳格子 该题有题解 时间限制:2457MS  内存限制:1000K提交次数:139 通过次数:46 题型: 编程题   语言: G++;GCC Description 地上有一个n*m 的数 ...

  8. P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 记忆化搜索dfs

    题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵 ...

  9. 【BZOJ4428】[Nwerc2015]Debugging调试 记忆化搜索+分块

    [BZOJ4428][Nwerc2015]Debugging调试 Description 你看中的调试器将不会在这件事上帮助你.有代码可以通过多种方式在调试与正式发布的间隙发生不同的行为,当出现这种情 ...

随机推荐

  1. 20162328蔡文琛 week06 大二

    20162328 2017-2018-1 <程序设计与数据结构>第6周学习总结 教材学习内容总结 队列元素按FIFO的方式处理----最先进入的元素最先离开. 队列是保存重复编码k值得一种 ...

  2. HDU 5229 ZCC loves strings 博弈

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5229 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  3. IO流详解

    目录 IO流 IO流概述及其分类 IO概念 流按流向分为两种: 流按操作类型分为两种: 常用的IO流类 字节流的抽象父类: 字符流的抽象父类: InputStream & FileInputS ...

  4. golang中的检验hash

    1.对字符串进行hash 大家可以看一下, SHA1 Hashes Go by Example写道: The pattern for generating a hash is sha1.New(), ...

  5. memached实现tomcat的session共享

    由于项目服务器用的阿里云的ECS,Memcached也采用的阿里云.多个tomcat集群的session都存储在一个云memcached中. 配置步骤如下: 一.tomcat增加memcached支持 ...

  6. 爬虫学习之-python插入mysql报错

    异常:'latin-1' codec can't encode characters in position 62-66: ordinal not in range(256) 用Python通过pym ...

  7. 【转载】mysql建表date类型不能设置默认值

    如题,mysql建表date类型的不能设置一个默认值,比如我这样: CREATE TABLE `new_table` ( `biryhday` datetime NULL DEFAULT '1996- ...

  8. Android Studio -导入项目 gradle处理

    如果导入 android studio 项目, 那么一定要注意 需要合适的gradle版本,具体方法为: 首先导入步骤: 打开android studio ==> File ==> New ...

  9. MYSQL-update与select结合使用

    使用 inner join   ) c ,," , iteration; 如上例子: 完成更新 picture.labels 字段 & picture.iteration自增 的两个 ...

  10. 平衡树以及AVL树

    平衡树是计算机科学中的一类数据结构. 平衡树是计算机科学中的一类改进的二叉查找树.一般的二叉查找树的查询复杂度是跟目标结点到树根的距离(即深度)有关,因此当结点的深度普遍较大时,查询的均摊复杂度会上升 ...