hdu - 1087 - Super Jumping! Jumping! Jumping!
2013-01-31 20:01
302 查看
题意:求最大升序和。
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087
——>>设d[i]表示以第i个数为终点的最大升序和,然后从第1个数到第i-1个数为终点的最大升序和进行检查,向后递推即可。
今天用Java做了一次:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087
——>>设d[i]表示以第i个数为终点的最大升序和,然后从第1个数到第i-1个数为终点的最大升序和进行检查,向后递推即可。
#include <iostream> #include <algorithm> using namespace std; int main() { int N, a[1010], i, j; long long d[1010]; //d[i]表示以第i个数为终点的最大升序和 while(cin>>N) { if(!N) return 0; for(i = 1; i <= N; i++) { cin>>a[i]; d[i] = a[i]; //最小为其自己,无左拓展 } long long max_sum = a[1]; //最大升序和存进max_sum for(i = 2; i <= N; i++) //第1个一定是它自己,故从第2个数开始 for(j = 1; j < i; j++) { if(a[j] < a[i]) d[i] = max(d[i], d[j]+a[i]); //如果是升序,更新 max_sum = max(max_sum, d[i]); //更新 } cout<<max_sum<<endl; } return 0; }
今天用Java做了一次:
import java.util.Scanner; public class Main { static final int maxn = 1000 + 10; public static void main(String[] args) { Scanner cin = new Scanner(System.in); int N, a[] = new int[maxn]; long d[] = new long[maxn]; while(cin.hasNextInt()){ N = cin.nextInt(); if(N == 0) break; for(int i = 1; i <= N; i++) d[i] = a[i] = cin.nextInt(); long max = -1; for(int i = 1; i <= N; i++) for(int j = 1; j < i; j++){ if(a[j] < a[i] && d[i] < d[j]+a[i]) d[i] = d[j]+a[i]; if(d[i] > max) max = d[i]; } System.out.println(max); } cin.close(); } }
相关文章推荐
- HDU - 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping! (最大 上升子序列 线性 dp)
- 【HDU】-1087-Super Jumping! Jumping! Jumping!(DP)
- hdu 1087 Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping! 【hdu-1087】【动态规划-最长上升子序列】
- HDU-1087-Super Jumping! Jumping! Jumping!(DP)
- HDU-1087-Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!(dp)【HDU】-1087
- HDU 1087 Super Jumping! Jumping! Jumping!(最长上升子序列,dp)
- HDU1087 Super Jumping! Jumping! Jumping!(动态规划,最大递增子段和)
- hdu 1087 Super Jumping! Jumping! Jumping!-dp 最长上升子序列和
- [HDU 1087 Super Jumping! Jumping! Jumping!] DP
- Super Jumping! Jumping! Jumping! HDU - 1087
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping! (DP)
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping! (DP,水题)
- HDU 1087 Super Jumping! Jumping! Jumping!
- HDU - 1087 Super Jumping! Jumping! Jumping! (简单LIS)
- HDOJ HDU 1087 Super Jumping! Jumping! Jumping!