标签:c style class blog code java
/* * @author Panoss */ #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<vector> #include<ctime> #include<stack> #include<queue> #include<list> using namespace std; #define DBG 1 #define fori(i,a,b) for(int i = (a); i < (b); i++) #define forie(i,a,b) for(int i = (a); i <= (b); i++) #define ford(i,a,b) for(int i = (a); i > (b); i--) #define forde(i,a,b) for(int i = (a); i >= (b); i--) #define forls(i,a,b,n) for(int i = (a); i != (b); i = n[i]) #define mset(a,v) memset(a, v, sizeof(a)) #define mcpy(a,b) memcpy(a, b, sizeof(a)) #define dout DBG && cerr << __LINE__ << " >>| " #define checkv(x) dout << #x"=" << (x) << " | "<<endl #define checka(array,a,b) if(DBG) { \ dout << #array"[] | " << endl; forie(i, a, b) cerr << "[" << i << "]=" << array[i] << " |" << ((i - (a)+1) % 5 ? " " : "\n"); if (((b)-(a)+1) % 5) cerr << endl; } #define redata(T, x) T x; cin >> x #define MIN_LD -2147483648 #define MAX_LD 2147483647 #define MIN_LLD -9223372036854775808 #define MAX_LLD 9223372036854775807 #define MAX_INF 18446744073709551615 inline int reint() { int d; scanf("%d", &d); return d; } inline long relong() { long l; scanf("%ld", &l); return l; } inline char rechar() { scanf(" "); return getchar(); } inline double redouble() { double d; scanf("%lf", &d); return d; } inline string restring() { string s; cin >> s; return s; } int h[105]; int f[105]; ///f[i] 表示为选择截击的第i个导弹,从这个导弹开始最多能截击的导弹数目 int DP(int n) { mset(f,0); f[n] = 1; ///初始化截击最后一枚导弹,最多只能截击一枚 int ans_max = 0; forde(i,n-1,1) { //checkv(i); int MAX = 0; forie(j,i+1,n) { if(h[j] <= h[i] && MAX < f[j]) { MAX = f[j]; //checkv(MAX); //checkv(j); //checkv(f[j]); } } f[i] = MAX + 1; ans_max = max(ans_max,f[i]); } return ans_max; } int main() { int n; while(scanf("%d",&n)==1&&n) { forie(i,1,n) scanf("%d",&h[i]); cout << DP(n) << endl; } }
标签:c style class blog code java
原文地址:http://www.cnblogs.com/Panoss/p/3779095.html