Hdu 1087 Super Jumping! Jumping! Jumping! (DP)
2014-03-11 22:15
381 查看
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087
思路:dp[i] 表示 在第i位置能够得到的最大分数,dp[i] = max(dp[j] if a[j]<a[i]) + a[i];
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 1000+5
#define LL __int64
int a[maxn];
LL dp[maxn];
int main(){
int n;
while(~scanf("%d",&n) , n){
for (int i = 1; i <= n; i++)
{
scanf("%d",&a[i]);
dp[i] = a[i];
}
LL ans = dp[1];
for (int i = 2; i <= n; i++)
{
for (int j = i; j >= 1; j--)
{
if(a[j] < a[i] && dp[i] < dp[j]+a[i])
dp[i] = dp[j]+a[i];
}
ans = max(ans,dp[i]);
}
printf("%I64d\n",ans);
}
return 0;
}
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087
思路:dp[i] 表示 在第i位置能够得到的最大分数,dp[i] = max(dp[j] if a[j]<a[i]) + a[i];
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 1000+5
#define LL __int64
int a[maxn];
LL dp[maxn];
int main(){
int n;
while(~scanf("%d",&n) , n){
for (int i = 1; i <= n; i++)
{
scanf("%d",&a[i]);
dp[i] = a[i];
}
LL ans = dp[1];
for (int i = 2; i <= n; i++)
{
for (int j = i; j >= 1; j--)
{
if(a[j] < a[i] && dp[i] < dp[j]+a[i])
dp[i] = dp[j]+a[i];
}
ans = max(ans,dp[i]);
}
printf("%I64d\n",ans);
}
return 0;
}
相关文章推荐
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- Android根据分辨率进行单位转换-(dp,sp转像素px)
- android 尺寸 dp,sp,px,dip,pt详解
- Android 不同分辨率下如何使字体大小随之变化
- HDU4758 AC自动机+DP (HDU4758与HDU2222)
- [LeetCode] Distinct Subsequences
- [LeetCode] Interleaving String
- [LeetCode] Unique Binary Search Tree
- [LeetCode] Edit Distance
- [LeetCode] Minimum Path Sum
- [LeetCode] Unique Paths
- [LeetCode] Unique Paths II
- [LeetCode] Maximum Subarray
- [LeetCode] Trapping Rain Water
- [LeetCode] Binary Tree Maximum Path Sum
- [LeetCode] Best Time to Buy and Sell Stock III
- [LeetCode] Scramble String
- [LeetCode] Longest Palindromic Substring
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers