【HDOJ】1160 FatMouse's Speed
DP。
#include <stdio.h>
#include <string.h>
#include <stdlib.h> #define MAXNUM 1005 typedef struct {
int w, s;
int index;
} mouse_st; mouse_st mouses[MAXNUM];
int dp[MAXNUM], next[MAXNUM]; int comp(const void *a, const void *b) {
mouse_st *p = (mouse_st *)a;
mouse_st *q = (mouse_st *)b;
if (p->w == q->w)
return p->s - q->s;
else
return q->w - p->w;
} int main() {
int n=, m, beg;
int i, j, max, index; while (scanf("%d %d", &mouses[n].w, &mouses[n].s) != EOF) {
mouses[n].index = n;
++n;
} memset(dp, , sizeof(dp));
qsort(mouses, n, sizeof(mouse_st), comp);
for (i=; i<n; ++i)
next[i] = i;
m = ; for (i=; i<n; ++i) {
max = ;
for (j=; j<i; ++j) {
if (mouses[j].w>mouses[i].w && mouses[j].s<mouses[i].s) {
if (max < dp[j]) {
max = dp[j];
index = mouses[j].index;
}
}
}
if (max)
next[mouses[i].index] = index;
dp[i] = max + ;
if (m < dp[i]) {
m = dp[i];
beg = mouses[i].index;
}
}
if (m == )
printf("1\n1\n");
else {
printf("%d\n", m);
while (next[beg] != beg) {
printf("%d\n", beg+);
beg = next[beg];
}
printf("%d\n", beg+);
} return ;
}
【HDOJ】1160 FatMouse's Speed的更多相关文章
- 【HDOJ】1009 FatMouse' Trade
这道题目是一道非常简单的贪心,但是我却修改了1h+.原因就是qsort的comp有bug.其实还是题目中的数据可以为0.除数为0真的要慎重啊.后来改为结构体,加一层循环选取最大值,果然ac啊.wa了几 ...
- 【HDOJ】1078 FatMouse and Cheese
这道题目是典型的DFS+记忆化搜索, DP思想.符合:含重叠子问题,无后效性等特点. #include <cstdio> #include <cstring> #include ...
- 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed
https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...
- HDU 1160 FatMouse's Speed(要记录路径的二维LIS)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1160 FatMouse's Speed (DP)
FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU - 1160 FatMouse's Speed 【DP】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...
- Hdoj 1160.FatMouse's Speed 题解
Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
随机推荐
- RazorEngine在非MVC下的使用,以及使用自定义模板
---恢复内容开始--- RazorEngine模板引擎大大的帮助了我们简化字符串的拼接与方法的调用,开源之后,现在在简单的web程序,winform程序,甚至控制台程序都可以利用它来完成. 但如何在 ...
- 20160330javaweb之session 小练习
练习一:session 实现登录注销 package com.dzq.session.logout; import java.util.*; public class UserDao { /** * ...
- MVC 避免黄页
可以使用HandleErrorAttribute 有两种方式可以使用它,在类或者方法的头上加 [HandleError] 这种直接在类或者方法上加[HandlerError]手动添加 另外一种方式是使 ...
- Oracle 11g之创建和管理表练习
创建表: SQL> create table name (empno number(4), ename VARCHAR2(10)); 查看表结构: desc name; SQL> desc ...
- html常用标签 第二节
直接上代码了 <html> <head> <title>我的第二个网页</title> </head> <body> <h ...
- js window.open 参数设置
function OpenWin(type, obj){ window.open ("http://www.baidu.com" + type, "_blank" ...
- 使用jeesite org.springframework.beans.NotReadablePropertyException: Invalid property 'tfxqCmsAccount.id' of bean class
一对多 对子表添加时在form表单 path="tfxqCmsAccount.id"页面报错,对比了下其他可行的,发现其自动生成的子类少了个构造方法 加上 public TfxqC ...
- PAT_1040 有几个PAT
问题描述: 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T):第二个PAT是第3位(P),第4位(A),第6位(T). 现给定字符串,问一共可以 ...
- hdu 1286 找新朋友 (欧拉函数)
Problem Description 新年快到了,"猪头帮协会"准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的 ...
- compass sprite
1.compass init 初始化一个compass项目,并创建一个images文件夹用来存放合成的sprite图 2.将切好的小图放到images文件夹中 3.在sass文件夹中新建一个test. ...