luogu3146 [USACO16OPEN]248
作者:互联网
细节被坑惨
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=1e6+5; 4 const int INF=1e9+7; 5 int n,ans,dp[305][305]; 6 template <class t>void red(t &x) 7 { 8 x=0; 9 int w=1; 10 char ch=getchar(); 11 while(ch<'0'||ch>'9') 12 { 13 if(ch=='-') 14 w=-1; 15 ch=getchar(); 16 } 17 while(ch>='0'&&ch<='9') 18 { 19 x=(x<<3)+(x<<1)+ch-'0'; 20 ch=getchar(); 21 } 22 x*=w; 23 } 24 void input() 25 { 26 freopen("input.txt","r",stdin); 27 } 28 void read() 29 { 30 red(n); 31 for(int i=1;i<=n;++i) 32 red(dp[i][i]); 33 } 34 void work() 35 { 36 for(int i=1;i<=n;++i) 37 for(int j=1;j+i<=n+1;++j) 38 { 39 int e=i+j-1; 40 for(int k=j;k<e;++k) 41 if(dp[j][k]==dp[k+1][e]) 42 dp[j][e]=max(dp[j][e],dp[j][k]+1); 43 ans=max(ans,dp[j][e]); 44 // else 45 // dp[j][e]=max(dp[j][e],max(dp[j][k],dp[k+1][e])); 46 } 47 printf("%d",ans); 48 } 49 int main() 50 { 51 //input(); 52 read(); 53 work(); 54 return 0; 55 }View Code
标签:ch,const,luogu3146,int,305,while,USACO16OPEN,248,getchar 来源: https://www.cnblogs.com/Achensy/p/10804490.html