题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数。Special Judge

思路:先按体重由小到大排序,再找最长速度递减序列。

转移方程:mou[i].w>mou[j].w&&mou[i].s<mou[j].s&&dp[j]+1>dp[i]

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define clc(a,b) sizeof(a,b,sizeof(a))
#define LL long long
#include<cmath>
using namespace std;
int dp[];//表示以i结尾的最长长度
int rightt[];//最终输出序列
int pre[];//记录i的前驱是什么
struct node {
int w,s,index;
} mou[]; bool cmp(node a,node b) {
if(a.w!=b.w) return a.w<b.w;
else return a.s>b.s;
} int main() {
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int k=;
while(scanf("%d%d",&mou[k].w,&mou[k].s)!=EOF) {
mou[k].index=k;
k++;
}
sort(mou+,mou+k,cmp);
clc(dp,);
clc(rightt,);
clc(pre,);
int tot=;
int last;
for(int i=; i<k; i++) {
for(int j=; j<i; j++) {
if(mou[i].w>mou[j].w&&mou[i].s<mou[j].s&&dp[j]+>dp[i]) {
dp[i]=dp[j]+;
pre[i]=j;
if(tot<dp[i]) {
tot=dp[i];
last=i;
}
}
}
}
int r=last;
int i=;
while(r!=) {
rightt[i++]=r;
r=pre[r];
}
printf("%d\n",i);
for(int j=i-; j>=; j--) {
printf("%d\n",mou[rightt[j]].index);
}
return ;
}

HDU FatMouse's Speed 基本DP的更多相关文章

  1. hdu FatMouse's Speed 动态规划DP

    动态规划的解决方法是找到动态转移方程. 题目地址:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=3&sectionid ...

  2. FatMouse's Speed 基础DP

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

  3. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  4. zoj 1108 FatMouse's Speed 基础dp

    FatMouse's Speed Time Limit: 2 Seconds      Memory Limit:65536 KB     Special Judge FatMouse believe ...

  5. HDU 1160 FatMouse's Speed LIS DP

    http://acm.hdu.edu.cn/showproblem.php?pid=1160 同样是先按它的体重由小到大排,相同就按speed排就行. 这样做的好处是,能用O(n^2)枚举,因为前面的 ...

  6. HDU 1160 FatMouse's Speed (sort + dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160 给你一些老鼠的体重和速度,问你最多需要几只可以证明体重越重速度越慢,并输出任意一组答案. 结构体 ...

  7. HDU 1160 FatMouse's Speed(DP)

    点我看题目 题意 :给你好多只老鼠的体重和速度,第 i 行代表着第 i 个位置上的老鼠,让你找出体重越大速度越慢的老鼠,先输出个数,再输出位置. 思路 :看题的时候竟然脑子抽风了,看了好久愣是没明白题 ...

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

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

  9. HDU 1160 FatMouse's Speed ——(DP)

    又是那个lis变形的题目. 但是不好定义严格的比较符号,因此只能n^2去做.值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题.但是要注意,因为要输出路径,所以要 ...

随机推荐

  1. Corosync+Pacemaker+DRBD+MySQL 实现高可用(HA)的MySQL集群

    大纲一.前言二.环境准备三.Corosync 安装与配置四.Pacemaker 安装与配置五.DRBD 安装与配置六.MySQL 安装与配置七.crmsh 资源管理 推荐阅读: Linux 高可用(H ...

  2. Python调试工具-Spyder

    OS:Windows 7 关键字:Python IDE, Spyder 1.安装工具pip:https://pip.pypa.io/en/latest/installing.html 下载 get-p ...

  3. SQLServer数据库通用访问类

    private static string connString=ConfigurationManager.ConnStrings["connString"].ToString() ...

  4. <二> SQL 基础

    left (outer) join 结果集包含连接表的匹配行,也包括左连接表的所有行. select a.a, a.b, a.c, b.c b.d b.f from a left out join b ...

  5. delphi xe5 android 控制蓝牙

    本文部分内容摘自: http://www.pclviewer.com/android/用以下代码中的接口实现控制蓝牙的开.关及详细信息 unit Androidapi.JNI.BluetoothAda ...

  6. Spatial Pyramid Matching 小结

    Spatial Pyramid Matching 小结 稀疏编码系列: (一)----Spatial Pyramid 小结 (二)----图像的稀疏表示——ScSPM和LLC的总结 (三)----理解 ...

  7. hdu 1423

    最长公共上升子序列:O(n*m)的算法: #include<cstdio> #include<cstring> #define maxn 1000 using namespac ...

  8. POJ2200+全排列模拟

    简单. 手动的实现全排列 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<a ...

  9. Android 自定义ToggleButton+用SharedPreferences保存用户配置

    布局文件:   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" androi ...

  10. asp.net web 开发登录相关操作的控件LoginName、LoginStatus和LoginView控件使用详解

    http://book.51cto.com/art/200909/154039.htm http://book.51cto.com/art/200909/154041.htm ASP.NET提供了一套 ...