标签:style blog color for div log sp amp c
1 void LICS() 2 { 3 for (int i=1;i<=n;i++) 4 { 5 int ma=0; 6 for (int j=1;j<=n;j++) 7 { 8 if (a[i]==b[j]) 9 f[i][j]=ma+1; 10 else f[i][j]=f[i-1][j]; 11 if (b[j]<a[i] && f[i-1][j]>ma) 12 ma=f[i-1][j]; 13 ans=max(ans,f[i][j]); 14 } 15 } 16 printf("%d\n",ans); 17 }
空间优化到一维:
1 void LICS() 2 { 3 for (int i=1;i<=n;i++) 4 { 5 int ma=0,tmp; 6 for (int j=1;j<=n;j++) 7 { 8 tmp=ma; 9 if (b[j]<a[i] && f[j]>ma) 10 ma=f[j]; 11 if (a[i]==b[j]) 12 f[j]=tmp+1; 13 ans=max(ans,f[j]); 14 } 15 } 16 printf("%d\n",ans); 17 }
标签:style blog color for div log sp amp c
原文地址:http://www.cnblogs.com/vb4896/p/3942726.html