最长上升子序列 && 最大字段和
package algorithm;
import java.util.Arrays;
public class TheLongestRising {
public static void main(String[] args) {
int dp[] =new int[9];
int a[] = {-1,3,100,4,-6,6,1,2,7};
dp[0]=1;
for(int i=1;i<=a.length-1;i++)
{
if(a[i]>=a[i-1])
{
dp[i]=dp[i-1]+1;
}else {
dp[i]=1;
}
}
System.out.println(Arrays.toString(dp));
}
}
package algorithm;
import java.util.Arrays;
public class MaximumFieldSum {
public static void main(String[] args) {
int dp[] =new int[9];
int a[] = {-1,3,-100,4,-6,6,1,2,7};
dp[0]=a[0];
for(int i=1;i<=a.length-1;i++)
{
if(dp[i-1]>=0)
{
dp[i]=dp[i-1]+a[i];
} else
{
dp[i]=a[i];
}
}
System.out.println(Arrays.toString(dp));
}
}