HDU 1024 拦截导弹
dp【i】表示为了拦截第i枚导弹最少需要多少个系统
状态转移方程
#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <string> #include <map> #include <iomanip> #include <algorithm> #include <queue> #include <stack> #include <set> #include <vector> //const int maxn = 1e5+5; #define ll long long ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} #define MAX INT_MAX #define FOR(i,a,b) for( int i = a;i <= b;++i) #define bug cout<<"--------------"<<endl using namespace std; int dp[31000],a[31000]; int main() { int n; while(cin>>n) { FOR(i,1,n) cin>>a[i]; int maxx = 0; for(int i=1;i<=n;++i) { dp[i] = 1; for(int j=1;j<i;++j) { if(a[i] > a[j]) dp[i] = max(dp[j]+1,dp[i]); } maxx = max(maxx,dp[i]); } cout<<maxx<<endl; } }