hdu 1160 FatMouse's Speed

来源:互联网 发布:unity3d引擎架构 编辑:程序博客网 时间:2024/06/08 14:59
#include <iostream>#include <cstring>#include <algorithm>using namespace std;#define N 1100struct node{    int w, s, num;};bool cmp (node a, node b){    if (a.w != b.w)        return a.w < b.w;    else        return a.s > b.s;}int main (){    node stu[N];    int n = 1, dp[N], path[N], ans1[N];    memset (dp, 0, sizeof(dp));    while (cin >> stu[n].w >> stu[n].s)        stu[n++].num = n, path[n-1] = n-1;    int ans = 0, index = 0;    sort (stu + 1, stu + n, cmp);    for (int i=1; i<n; i++)    {        dp[i] = 1;        for (int j=i; j>=1; j--)        {            if (stu[j].w < stu[i].w && stu[j].s > stu[i].s)            {                if (dp[j] + 1 > dp[i])                {                    dp[i] = dp[j] + 1;                    path[stu[i].num] = stu[j].num;                }            }            if (dp[i] > ans) ans = dp[i], index = stu[i].num;        }    }    cout << ans << endl;    int k = 0;    while (path[index] != index)    {        ans1[k++] = index;        index = path[index];    }    ans1[k] = index;    for (int i=k; i>=0; i--)        cout << ans1[i] << endl;    return 0;}

0 0
原创粉丝点击