【BZOJ】1270: [BeijingWc2008]雷涛的小猫(DP+水题)
http://www.lydsy.com/JudgeOnline/problem.php?id=1270
这完全是一眼题啊,但是n^2的时间挺感人。(n^2一下的级别请大神们赐教,我还没学多少dp优化。。)
一眼是n^3的,但是马上可以想到n^2的,用一个数组维护每层最大就行了。
在这里,dp的数组开n^2和存图的数组开n^2用int的话一定爆,存图的用short可以水过。但是看方程我们可以很自然的想到用滚动数组,那么dp的数组就变成一维的啦~ac无压力。
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define for1(i,a,n) for(i=a;i<=n;++i)
#define for2(i,a,n) for(i=a;i<n;++i)
#define for3(i,a,n) for(i=a;i>=n;--i)
#define for4(i,a,n) for(i=a;i>n;--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define read(a) scanf("%d", &a)
#define print(a) printf("%d", a) inline int getnum() {
int ret=0; char c;
for(c=getchar(); c<'0' || c>'9'; c=getchar());
for(; c>='0' && c<='9'; c=getchar()) ret=ret*10+c-'0';
return ret;
} const int N=5005; int imap[N][N];
int d[N], maxi[N]; int main() {
int n, h, de, i, j, t, ans=0;
n=getnum(); h=getnum(); de=getnum();
for1(i, 1, n) {
t=getnum();
for1(j, 1, t)
++imap[getnum()][i];
}
for3(i, h, 1) {
for1(j, 1, n) {
d[j]=max(d[j], maxi[i+de])+imap[i][j];
maxi[i]=max(maxi[i], d[j]);
}
ans=max(ans, maxi[i]);
}
print(ans);
return 0;
}
Description

Input

Output

Sample Input

Sample Output
HINT

Source
【BZOJ】1270: [BeijingWc2008]雷涛的小猫(DP+水题)的更多相关文章
- BZOJ 1270: [BeijingWc2008]雷涛的小猫( dp )
简单的dp.. dp(i,j) = max(dp(x,y))+cnt[i][j], (x,y)->(i,j)是合法路径. 设f(i)= max(dp(x,y))(1≤x≤N, 1≤y≤i), g ...
- bzoj 1270: [BeijingWc2008]雷涛的小猫 简单dp+滚动数组
1270: [BeijingWc2008]雷涛的小猫 Time Limit: 50 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Descrip ...
- [bzoj 1270][BeijingWc2008]雷涛的小猫
Description 雷涛的小猫雷涛同学非常的有爱心,在他的宿舍里,养着一只因为受伤被救助的小猫(当然,这样的行为是违反学 生宿舍管理条例的). 在他的照顾下,小猫很快恢复了健康,并且愈发的活泼可 ...
- 【BZOJ1270】1270: [BeijingWc2008]雷涛的小猫 DP
Description Input Output Sample Input Sample Output 8 HINT Source 唉这么蠢的Dp没一下子看出来,Dp真是太弱了啦. #includ ...
- 1270: [BeijingWc2008]雷涛的小猫
1270: [BeijingWc2008]雷涛的小猫 Time Limit: 50 Sec Memory Limit: 162 MBSubmit: 905 Solved: 430[Submit][ ...
- bzoj1270 BeijingWc2008 雷涛的小猫 DP
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1270 比较水的一道dp f1[i]为高度为i的时候的最大值 f2[i]为当前高度在第i棵树 ...
- B1270 [BeijingWc2008]雷涛的小猫 dp
这个题的原始方法谁都会,但是n^3会T.之后直接优化,特别简单,就是每次处理出来每层的最大值,而不用枚举.之前没这么做是因为觉得在同一棵树的时候没有下落,所以不能用这个方法.后来想明白了,在同一棵树上 ...
- 【BZOJ】1270 [BeijingWc2008]雷涛的小猫
[算法]DP [题解]f1[i]表示第i棵树当前高度能得到的最多果子数 f2[i]表示高度i能得到的最多果子数. 于是有: f1[j]=max(f1[j],f2[i+delta])+mp[j][i]; ...
- 【bzoj1270】[BeijingWc2008]雷涛的小猫 dp
题目描述 输入 输出 样例输入 样例输出 8 题解 dp 设f[i][j]表示在第i棵树的j高度时最多吃到的柿子数. 那么只有两种可能能够到达这个位置:滑下来.跳下来. 滑下来直接用f[i][j+ ...
随机推荐
- poj2993 翻转2996
Emag eht htiw Em Pleh Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2944 Accepted: ...
- swiper组件实现向上翻页时缩小
var mySwiper = new Swiper ('.swiper-container', { direction: 'vertical', loop: true, // 如果需要前进后退按钮 n ...
- 【leetcode】Combination Sum II
Combination Sum II Given a collection of candidate numbers (C) and a target number (T), find all uni ...
- 74 使用BitSet输出数组中的重复元素
[本文链接] http://www.cnblogs.com/hellogiser/p/using-bitset-to-print-duplicate-elements-of-array.html [题 ...
- 【JAVA、C++】LeetCode 001 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The ...
- [MAC] Mac OS X下快速复制文件路径的方法
在windows上复制当前目录的路径有一个特别方便的方式,只需要用鼠标点击路径栏,它就会自动变成像”D:\Downloads\tmp”这样的路径,如果要复制文件路径,只需要将目录路径和文件名拼接起来即 ...
- August 4th, 2016, Week 32nd, Thursday
How does the world look through your eyes? 你眼中的世界是什么样的呢? This morning I saw a girl that is just the ...
- sublime 实用 快捷键
alt+- 向后导航 alt+shift+- 向前导航 ctrl+shift+↑↓ 上下移动一行 ctrl+k,ctrl+u 转换所选为大写 ctrl+k,ctrl+l(字母L) 转换所选为小写 ct ...
- BP神经网络模型与学习算法
一,什么是BP "BP(Back Propagation)网络是1986年由Rumelhart和McCelland为首的科学家小组提出,是一种按误差逆传播算法训练的多层前馈网络,是目前应用最 ...
- cf_ducational Codeforces Round 16_D(gcd)
题意:求R-L区间满足x=a1*k+b1=a2*l+b2的x的个数; 思路:求出最小的满足条件的x0,则ans=(L-x)/(a1/gcd(a1, a2)*a2)+1; 注意剪枝,不然会超时: 代码: ...