动态规划_拦截导弹
2015-08-19 09:28
204 查看
被拦截的导弹应该按照飞来的高度组成一个非递增序列。求最长非递增序列的长度。
#include <iostream>
using namespace std;
int main()
{
int h[2000], d[2000], c; //h表示 高度值, d表示最优值, c是能拦截的最多导弹数
int count = 0; //统计飞来的导弹数
while (cin >> h[count++] && h[count-1]); //输入高度
d[count-1] = 1; // d
= 1
c = 1; //用动态规划计算所有的最优值
for (int i = count - 2; i>=0; --i)
{
int max = 0;
for (int j = i+1; j<count; ++j)
{
if ((h[i] >= h[j]) && max < d[j])
max = d[j];
}
d[i] = max + 1;
if (c < d[i])
c = d[i];
}
cout << c << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int h[2000], d[2000], c; //h表示 高度值, d表示最优值, c是能拦截的最多导弹数
int count = 0; //统计飞来的导弹数
while (cin >> h[count++] && h[count-1]); //输入高度
d[count-1] = 1; // d
= 1
c = 1; //用动态规划计算所有的最优值
for (int i = count - 2; i>=0; --i)
{
int max = 0;
for (int j = i+1; j<count; ++j)
{
if ((h[i] >= h[j]) && max < d[j])
max = d[j];
}
d[i] = max + 1;
if (c < d[i])
c = d[i];
}
cout << c << endl;
return 0;
}
相关文章推荐
- OverFeat Integrated Recognition, Localization and Detection using Convolutional Networks
- android 源码在线
- Hadoop导航:版本、生态圈及MapReduce模型
- C#精髓 第四讲 GridView 72般绝技
- MAVEN环境变量配置
- hdu4419 Colourful Rectangle(离散,线段树,线扫描,状压)
- ALBB 找公共最长连续字母序列的长度
- java中计算两个时间差
- 关于从一个Fragment跳转到一个Activity中
- 动态规划_拦截导弹
- 时间戳
- 【C#】窗体动画效果
- win7下通过easyBCD引导安装Ubuntu14.04
- 非常难得的iPad版房地产售楼助手应用源码项目
- 线程同步与互斥:读写锁
- 第9章 Servlet的配置与使用
- C#多态性详解
- DeepID算法实践
- node.js基础:模块的创建和引入
- 删除的思路