标签:
一、原题
8 389 207 155 300 299 170 158 65
2
二、代码
1.简单模拟
/*********************************
日期:2015-06-03
作者:matrix68
题号: HDU 1257 - 最少拦截系统
总结:模拟
思路1:用一个Mhigh数组记录所有导弹拦截系统目前支持的最高高度
每次查找可拦截arr[i]的导弹系统中Mhigh[i]最低的一个
并更新他的Mhigh[i]为arr[i]
最后输出Mhigh容量即可
Tricks:题目并未给出容量,注意数组开大一点
**********************************/
#include <cstdio>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <cmath>
#define MP(a, b) make_pair(a, b)
#define PB push_back
#define Lowbit(x) ((x) & (-x))
#define Rep(i,n) for(int i=0;i<n;i++)
#define mem(arr,val) memset((arr),(val),(sizeof (arr)))
#define LL long long
const double PI = acos(-0);
const int MAXN = 10000 + 10;
const int MOD = 1000007;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
using namespace std;
int arr[MAXN];
int Mhigh[MAXN];
int main()
{
// freopen("in.txt","r",stdin);
int n;
while(~scanf("%d",&n))
{
Rep(i,n)
{
scanf("%d",&arr[i]);
}
int index=0;
Mhigh[index++]=arr[0];
for(int i=1;i<n;i++)
{
int j=0;
int minklj=-1;
for(j;j<index;j++)
{
if(arr[i]<Mhigh[j])
{
if(minklj!=-1&&Mhigh[j]<Mhigh[minklj])
minklj=j;
else if(minklj==-1)
minklj=j;
}
}
if(minklj!=-1)
Mhigh[minklj]=arr[i];
else
Mhigh[index++]=arr[i];
}
cout<<index<<endl;
}
return 0;
}
/*********************************
日期:2015-06-03
作者:matrix68
题号: HDU 1257 - 最少拦截系统
总结:DP
思路2:对于每个系统,如果能够拦截arr[i],则必然不能再拦截比arr[i]大的那个。
所以这里我们直接求最长严格上升序列
Tricks:题目并未给出容量,注意数组开大一点
**********************************/
#include <cstdio>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <cmath>
#define MP(a, b) make_pair(a, b)
#define PB push_back
#define Lowbit(x) ((x) & (-x))
#define Rep(i,n) for(int i=0;i<n;i++)
#define mem(arr,val) memset((arr),(val),(sizeof (arr)))
#define LL long long
const double PI = acos(-0);
const int MAXN = 10000 + 10;
const int INF = 99999;
const int MOD = 1000007;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
using namespace std;
int arr[MAXN];
int dp[MAXN];
int main()
{
// freopen("in.txt","r",stdin);
int n;
while(~scanf("%d",&n))
{
Rep(i,n)
{
scanf("%d",&arr[i]);
dp[i]=1;
}
int ans=-INF;
for(int i=0;i<n;i++)
{
for(int j=0;j<i;j++)
{
if(arr[j]<arr[i])
{
dp[i]=max(dp[j]+1,dp[i]);
}
}
if(dp[i]>ans)
ans=dp[i];
}
cout<<ans<<endl;
}
return 0;
}
DP46道 - 第21题 - 拦截系统 两种算法 DP/模拟
标签:
原文地址:http://blog.csdn.net/chrome_matrix_68/article/details/46350867