首页 > 代码库 > [ An Ac a Day ^_^ ] hdu 1003 dp

[ An Ac a Day ^_^ ] hdu 1003 dp

超时还有可能是数组开小了……

 1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<string> 7 #include<map> 8 #include<set> 9 #include<vector>10 #include<queue>11 #define M(a) memset(a,0,sizeof(a))12 using namespace std;13 typedef long long ll;14 int num[100005];15 int dp[100005];16 int from[100005];17 int main(){18     int T,case_=1;19     scanf("%d",&T);20     while(T--){21         int n;22         scanf("%d",&n);23         scanf("%d",&num[1]);24         int nowmax=num[1],nowa=1,nowb=1;25         int ans=num[1],a=1,b=1;26         for(int i=2;i<=n;i++){27             scanf("%d",&num[i]);28             if(num[i]+nowmax<num[i]){29                 nowmax=num[i];30                 nowa=i;31             }32             else nowmax+=num[i];33             if(ans<nowmax){34                 ans=nowmax;35                 a=nowa;36                 b=i;37             }38         }39         printf("Case %d:\n",case_++);40         printf("%d %d %d\n",ans,a,b);41         if(T!=0) puts("");42     }43     return 0;44 }45 /*46 47 1148 1 649 79 12 -22 -8 -2 -19 -7 5 -5 17 14 -22 7 -5 -13 -25 -24 21 12 10 13 12 22 20 -15 -12 -10 -15 -13 -17 14 2 -25 -22 11 -3 -15 18 23 15 8 -2 19 4 -18 -20 21 -1 1 19 20 -4 -9 5 -7 -19 9 20 -21 0 -22 -5 -13 15 0 -1 24 -17 8 8 -17 19 -4 -16 20 15 21 -11 -12 -2350 67 -5 -23 24 21 11 6 21 11 -7 -25 -23 8 -7 5 -13 24 -24 13 1 -5 6 -11 -1 1 10 21 -9 -7 -15 -4 -25 7 -5 -3 11 20 16 7 14 7 -8 0 -23 -3 6 -24 8 -5 6 -22 -16 15 -19 -3 -1 -2 -2 20 24 -8 6 -19 -15 -25 -14 -25 1351 17 1 -21 -14 13 -19 -18 -24 -21 -13 8 -2 -4 8 4 -4 -23 2452 28 15 11 16 10 -16 -4 0 -25 -16 23 20 1 -7 -12 6 -20 -22 17 2 2 -23 -25 17 12 -21 6 -3 553 36 -6 22 1 -6 -5 1 5 -20 -15 -6 11 -5 -11 -10 3 16 20 -4 8 20 17 8 -7 9 -4 13 2 21 16 -20 -25 21 -13 3 -18 1754 71 14 -22 24 -3 -4 14 -22 24 13 -22 -13 14 -4 20 -19 4 17 -9 0 -18 18 7 -19 -20 -22 -25 -16 -10 7 -15 -16 -17 -1 -7 22 -12 13 -14 8 -4 12 -16 -5 -4 17 -13 4 -21 -18 -8 -9 -13 -23 5 -25 -18 5 24 -14 5 -7 -24 -2 -12 24 -16 20 21 -2 -15 -1155 64 -22 19 18 6 12 9 -5 10 -24 22 22 5 -3 -20 -21 18 24 3 9 7 13 -2 7 5 24 -12 6 -9 -10 12 -3 -21 -4 24 -7 -5 -8 22 -1 -16 -16 10 -11 -21 24 -3 3 -9 22 -7 6 -3 -6 6 23 -12 3 -17 -10 -9 -18 23 6 -956 71 17 10 -21 -10 -3 1 8 -21 16 -4 -23 -19 4 7 17 18 5 -25 -15 7 -2 -10 11 14 -11 -2 -11 11 14 20 19 -19 -18 7 -6 6 18 -20 12 -14 -6 -14 -13 -10 -23 -11 -24 9 6 -6 6 -25 8 14 -8 14 -17 2 -8 24 -11 -21 -18 5 6 4 -20 -11 3 -3 1957 12 -25 -9 -20 5 15 15 -15 -10 -15 -17 -13 2358 58 22 -20 -22 -25 1 -6 -7 -23 6 16 -17 -5 -23 -24 -9 -2 -16 23 7 14 16 19 -21 -5 6 10 -10 -23 0 -18 9 17 10 1 19 -23 15 7 -3 15 -17 -20 -23 22 -16 -1 -14 10 0 -17 2 -19 16 -6 -23 -25 -6 -1259 60 */

 

[ An Ac a Day ^_^ ] hdu 1003 dp