拦截导弹
http://acm.nyist.net/JudgeOnline/problem.php?pid=79
不明白哪儿有问题,有待验证
1 #include <stdio.h> 2 3 int floor = 0; 4 void recurring(int missile[],int begin,int size,int& cur){ 5 ++cur; 6 if(begin >= size - 1) 7 return ; 8 int i; 9 for(i = begin; i < size; i++){ 10 if(missile[i] < missile[begin]){ 11 recurring(missile,i,size,cur); 12 floor = (floor > cur) ? floor : cur; 13 --cur; 14 } 15 } 16 } 17 18 int main(){ 19 int N; 20 int m; 21 int missile[50]; 22 int i,cur; 23 scanf("%d",&N); 24 while(N--){ 25 scanf("%d",&m); 26 cur = 0; 27 for(i = 0; i < m; i++) 28 scanf("%d",&missile[i]); 29 recurring(missile,0,m,cur); 30 printf("%d\n",floor); 31 floor = 0; 32 } 33 return 0; 34 }
不明觉厉,为啥还不对
1 #include <stdio.h> 2 #include <iostream> 3 #include <algorithm> 4 using namespace std; 5 #define M 50 6 int res[M]; 7 void dp(int missile[],int cur,int Size){ 8 if(cur < 0) return ; 9 for(int i = Size - 1; i > cur; i--){ 10 if(missile[cur] > missile[i]){ 11 res[cur] = (res[cur] > res[i]) ? res[cur] : res[i] + 1; 12 } 13 } 14 dp(missile,cur - 1,Size); 15 } 16 17 int main(){ 18 int N; 19 int m; 20 int missile[50]; 21 int i; 22 scanf("%d",&N); 23 while(N--){ 24 fill(res,res+50,1); 25 scanf("%d",&m); 26 for(i = 0; i < m; i++) 27 scanf("%d",&missile[i]); 28 dp(missile,m - 2,m); 29 printf("%d\n",res[0]); 30 } 31 return 0; 32 }
又失败了|-_-|
1 #include <stdio.h> 2 #include <iostream> 3 #include <algorithm> 4 using namespace std; 5 int main(){ 6 int N; 7 int m; 8 int missile[50],res[50]; 9 int i; 10 scanf("%d",&N); 11 while(N--){ 12 fill(res,res+50,1); 13 scanf("%d",&m); 14 for(i = 0; i < m; i++) 15 scanf("%d",&missile[i]); 16 for(int j = m-2; j >= 0; j--){ 17 for(int i = m - 1; i > j; i--){ 18 if(missile[j] > missile[i]){ 19 res[j] = (res[j] > res[i]) ? res[j] : res[i] + 1; 20 } 21 } 22 } 23 printf("%d\n",res[0]); 24 } 25 return 0; 26 }