杭电ACM1160——FatMouse's Speed
来源:互联网 发布:淘宝童装便宜货源 编辑:程序博客网 时间:2024/05/21 21:42
这题,很明显的动态规划。
按照老鼠的重量从小到大排序,重量一样的,按速度从大到小排序。
然后进行动态规划,dp[i] = dp[j] + 1;(符合条件的)
还有一点比较重要,就是输出的不唯一,样例的 4 4 5 9 7 和 4 4 5 9 8 都是对的。我输出的是4 4 5 9 8
下面的AC的代码:
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;struct data{int w, s;int i;};data num[1005];int dp[1005];int d[1005];int cmp(data a, data b){if(a.w != b.w)return a.w < b.w;elsereturn a.s > b.s;}int main(){//freopen("3.txt", "r", stdin);int n = 1, i, j;int maxlen = 0, maxindex = -1;for(i = 0; i < 1005; i++)dp[i] = 1;memset(d, 0, sizeof(d));while(cin >> num[n].w >> num[n].s){num[n].i = n;n++;}dp[1] = 1;sort(num + 1, num + n, cmp);for(i = 1; i < n; i++){for(j = 1; j < i; j++){if(num[i].w > num[j].w && num[i].s < num[j].s && dp[i] < dp[j] + 1){dp[i] = dp[j] + 1;d[i] = j;if(maxlen < dp[i]){maxindex = i;maxlen = dp[i];}}}}int ans[1000];int t = maxindex;i = 0;while(t != 0){ans[i++] = num[t].i;t = d[t];}cout << i << endl;for(j = i - 1; j >= 0; j--)cout << ans[j] << endl;return 0;}
0 0
- 杭电ACM1160——FatMouse's Speed
- 动态规划—杭电1160 FatMouse's Speed
- 杭电OJ :1160 FatMouse's Speed
- HDOJ 1160 FatMouse's Speed 杭电 ACM
- 杭电1160-FatMouse's Speed(超详细解释)
- HDU1160——FatMouse's Speed
- hdu 1160——FatMouse's Speed
- 15HD_OJ——FatMouse's Speed
- hdu(1160)——FatMouse's Speed
- HDU1160——FatMouse's Speed(DP入门)
- HUD 1160 FatMouse's Speed——LIS
- FatMouse's Speed
- zoj_1108 Fatmouse's Speed
- 【DP】FatMouse's Speed
- FatMouse's Speed(dp)
- FatMouse's Speed
- 1160FatMouse's Speed
- FatMouse's Speed
- 3GPP 36211-c70-4
- 移动端环境搭建--Chrome篇
- 03_Java 泛型
- 第6章2节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-获取命令字串
- Maximum Product Subarray
- 杭电ACM1160——FatMouse's Speed
- WCF程序的发布
- Maven工程使用Log4j
- Spring-Aop注解形式案例<三>
- shell之读取/etc/passwd中user及其id
- Parse Generator + Visual Studio 2013配置方法
- iOS推送相关注意点
- Android 使用imageLoader来加载显示图片
- 12.7 coding-python-mongo相关代码笔记