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的更多相关文章

  1. 【HDOJ】1009 FatMouse' Trade

    这道题目是一道非常简单的贪心,但是我却修改了1h+.原因就是qsort的comp有bug.其实还是题目中的数据可以为0.除数为0真的要慎重啊.后来改为结构体,加一层循环选取最大值,果然ac啊.wa了几 ...

  2. 【HDOJ】1078 FatMouse and Cheese

    这道题目是典型的DFS+记忆化搜索, DP思想.符合:含重叠子问题,无后效性等特点. #include <cstdio> #include <cstring> #include ...

  3. 【最长上升子序列记录路径(n^2)】HDU 1160 FatMouse's Speed

    https://vjudge.net/contest/68966#problem/J [Accepted] #include<iostream> #include<cstdio> ...

  4. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDU 1160 FatMouse's Speed (DP)

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  6. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDU - 1160 FatMouse's Speed 【DP】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1160 题意 给出一系列的 wi si 要找出一个最长的子序列 满足 wi 是按照升序排列的 si 是按 ...

  8. Hdoj 1160.FatMouse's Speed 题解

    Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove th ...

  9. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

随机推荐

  1. oracle 11g 64位安装sqldeveloper打开不了

    oracle 11g 64位安装sqldeveloper打开不了解决方法: 1.到官网下载对应版本的sqldeveloper. 2.找对应安装路径下的F:\app\Administrator\prod ...

  2. JS获取日期和时间

    //获取日期和时间 function showDate(){ var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFul ...

  3. nvidia安装与卸载方式

    第1种方法:.最好的方式不是手动安装官方驱动(手动安装官方驱动无法使用gpu,而且无法启用3d,同时无法生效,所以最好采用此种方法),而是使用bumblebee-nvidia安装,不过要先添加x-sw ...

  4. OC-手动内存管理

    一.为什么要进行内存管理 •移动设备的内存极其有限,每个app所能占用的内存是有限制的 • •下列行为都会增加一个app的内存占用 Ø创建一个OC对象 Ø定义一个变量 Ø调用一个函数或者方法 • •当 ...

  5. JAVA中实现百分比

    import java.text.NumberFormat; public class TeachYou { public static void main(String[] args) { //这里 ...

  6. 14_输出映射2_resultMap

    [resultMap] 如果查询出来的列名和pojo的属性名不一致,通过定义一个resultMap对列名和pojo属性名之间做一个映射列表. 1.定义resultMap,(在UserMapper.xm ...

  7. bzoj1231: [Usaco2008 Nov]mixup2 混乱的奶牛

    思路:状压dp,设f[i][j]表示当前已经选出的牛的状态为i,最后一头选出的牛为j的方案数. 然后注意就是初值不能是f[0][i]=1,因为所有牛本来都可以第一个被选中,然而这样一定初值有些牛可能就 ...

  8. 嵌入Web资源的方法

    可以将js .图片.css等嵌入Assembly中,这样就不用将文件在aspx中写了,特别适合做自定义控件的时候将控件用到的资源打包. 将文件放到项目的合适路径,比如jpg文件所在路径的namespa ...

  9. 快速设置IP的脚本

    @echo off cls ::set NAME="本地连接" set NAME="无线网络连接" set IP=192.168.1.55 set MASK=2 ...

  10. b+树 b-树的区别

    B+树与B*树小结 一.B+树 1.B+树定义与特性 B+树是B-树的变体,也是一种多路搜索树: 其定义基本与B-树同,除了: 1).非叶子结点的子树指针与关键字个数相同: 2).非叶子结点的子树指针 ...