POJ 1050 to the max
2014-11-10 20:18
267 查看
/*
这是一道DP题
首先我们得明白一种题的做法
就是给n个数,让你输出其中一段连续字串和的最大值
*/
//以上是简单的数学问题,自己在本子上画画就知道是为啥了
这是一道DP题
首先我们得明白一种题的做法
就是给n个数,让你输出其中一段连续字串和的最大值
*/
1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 int main() 5 { 6 int num[10000]; 7 int n; 8 cin>>n; 9 int temp=0; 10 int max=-100000; 11 for(int i=0;i<n;i++) 12 { 13 cin>>num[i]; 14 if(temp>0) 15 temp+=num[i]; 16 else 17 temp=num[i]; 18 if(max<temp) 19 max=temp; 20 cout<<max<<" "; 21 } 22 printf("\n"); 23 cout<<max<<endl; 24 return 0; 25 }
//以上是简单的数学问题,自己在本子上画画就知道是为啥了
1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 int m[101][101]; 5 int main() 6 { 7 int n,max,i,j,tmp,k; 8 while(cin>>n) 9 { 10 max=-10000; 11 for(i=0;i<n;i++) 12 { 13 tmp=0; 14 for(j=0;j<n;j++) 15 { 16 cin>>m[i][j]; 17 if(tmp>0) 18 tmp+=m[i][j]; 19 else 20 tmp=m[i][j]; 21 if(tmp<max) 22 max=tmp; 23 } 24 }//计算出哪一行中最大的连续字串和 25 for(i=0;i<n;i++) 26 { 27 for(j=i+1;j<n;j++) 28 { 29 tmp=0; 30 for(k=0;k<n;k++) 31 { 32 m[i][k]+=m[j][k]; 33 if(tmp>0)tmp+=m[i][k]; 34 else tmp=m[i][k]; 35 if(tmp>max)max=tmp; 36 } 37 } 38 } 39 cout<<max<<endl; 40 }//类似一个前缀和的操作,然后直接类似于前文的操作直接暴力扫一遍即可 41 return 0; 42 }
相关文章推荐
- POJ 1050-To the Max (动态规划)
- POJ 1050 To the Max
- zoj 1074 || poj 1050 To the Max(简单DP)
- poj 1050 To the Max
- POJ 1050 To the Max(最大子段)
- poj 1050 To the Max
- poj 1050 To the Max
- POJ 1050 To the Max【最大子矩阵】
- POJ 1050 To the Max (动态规划——求最大子矩阵和)
- POJ-1050-To the Max 解题报告
- POJ 1050 To the Max
- POJ 1050 To the Max
- POJ 1050 To the Max
- poj 1050 To the Max
- 【原】 POJ 1050 To the Max 求二维矩阵的最大子矩阵 解题报告
- DP::Poj1050 To the max
- POJ 1050 To the Max
- poj1050 To the Max
- POJ_1050_To the Max
- POJ 1050 To the max 最大子矩阵