LightOJ 1017 - Brush (III) 记忆化搜索+细节
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) 记忆化搜索+细节的更多相关文章
- Lightoj 1017 - Brush (III)
1017 - Brush (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sam ...
- lightOJ 1017 Brush (III) DP
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...
- 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 ...
- lightoj 1283 - Shelving Books(记忆化搜索+区间dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1283 题解:这题很显然一看就像是区间dp,但是单纯的区间dp好像解决不了问题可 ...
- LA 6042 Bee Tower 记忆化搜索
一开始读漏了很多细节,用递推写死活跑不出样例. 把题目中的细节列一下吧,状态方程很好推,改成记忆化搜索之后代码也很清晰. 1.蜜蜂需要到最高的塔去,最高的塔可能不止一个,抵达任意一个即可. 2.蜜蜂每 ...
- Codevs_1017_乘积最大_(划分型动态规划/记忆化搜索)
描述 http://codevs.cn/problem/1017/ 给出一个n位数,在数字中间添加k个乘号,使得最终的乘积最大. 1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提 ...
- 8636 跳格子(dfs+记忆化搜索)
8636 跳格子 该题有题解 时间限制:2457MS 内存限制:1000K提交次数:139 通过次数:46 题型: 编程题 语言: G++;GCC Description 地上有一个n*m 的数 ...
- P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm 记忆化搜索dfs
题目描述 每年,在威斯康星州,奶牛们都会穿上衣服,收集农夫约翰在N(1<=N<=100,000)个牛棚隔间中留下的糖果,以此来庆祝美国秋天的万圣节. 由于牛棚不太大,FJ通过指定奶牛必须遵 ...
- 【BZOJ4428】[Nwerc2015]Debugging调试 记忆化搜索+分块
[BZOJ4428][Nwerc2015]Debugging调试 Description 你看中的调试器将不会在这件事上帮助你.有代码可以通过多种方式在调试与正式发布的间隙发生不同的行为,当出现这种情 ...
随机推荐
- Python if后直接跟数字或字符串
(1)如果if后面的条件是数字,只要这个数字不是0,python都会把它当做True处理,见下面的例子 if 15: print 'YES' 输出YES,但是如果数字是0,就会被认为是False. ( ...
- vs中如何使用NuGet
在vs中如何打开NuGet? 1.工具→NuGet程序包管理器→程序包管理控制台 2.没有的话,就去 工具→扩展和更新 搜索nuget 如果你点击工具,没看到Nuget这些字样,请注意汉化名字为 ...
- lintcode-81-数据流中位数
81-数据流中位数 数字是不断进入数组的,在每次添加一个新的数进入数组的同时返回当前新数组的中位数. 说明 中位数的定义: 中位数是排序后数组的中间值,如果有数组中有n个数,则中位数为A[(n-1)/ ...
- 【acm】杀人游戏(hdu2211)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2211 杀人游戏 Time Limit: 3000/1000 MS (Java/Others) M ...
- mysql中用户和权限
用户管理 用户数据所在位置: mysql中的所有用户,都存储在系统数据库(mysql)中的user 表中——不管哪个数据库的用户,都存储在这里. 表初始内容如下: 创建用户: 形式: create ...
- word批量转pdf文件快捷方法。
最近在工作中因为要遇到大量的Word文件转化为PDF文件来实现平台的迁移.但是由于文件太多,手动很费力,想到了用代码的方式: 复制下面的代码,保存的记事本,另存为vbs文件:然后把这个vbs文件放到你 ...
- inno setup 打包exe程序
inno setup 用于打包生成安装程序, 是通过的一个脚本 可以将 exe 执行文件以安装的形式,解压,添加依赖,创建快捷方式. 例如,我们写了个winform,我们怎么通过安装的形式,给客户的机 ...
- python while 学习
while True: reply = input('please input:') if reply == 'stop': break else: print (reply.upper())
- Going in Cycle!! UVA - 11090(二分+判断环路 )
题意: 给定一个n个点m条边的加权有向图,求平均权值最小的回路 解析: 首先肯定是想到找出环路 然后..呵..呵..呵呵... 显然不现实!! 二分大法好 ....去猜结果 然后带入验证 ...真是 ...
- 【基础】一个简单的MVC实例及故障排除
Controller: public ActionResult Index() { string setting = "ApplicationServices"; var conn ...