- 论坛徽章:
- 145
|
本帖最后由 jason680 于 2012-06-12 19:39 编辑
回复 1# sequencing
how about this
$ awk '{for(n=0;n++<NF;)s[NR,n]=a[NR,n]=$n}END{c[0,0]=1;for(n=NR;n>1;n--)for(t=0;++t<n;)if(s[n,t]>s[n,t+1]){c[n-1,t]=t;s[n-1,t]+=s[n,t]}else{c[n-1,t]=t+1;s[n-1,t]+=s[n,t+1]};m=0;for(n=0;n++<NR;){for(p=NR-n;p-->0;)printf " ";for(t=0;t++<n;){if(c[n-1,m]==t)a[n,t]="\033[31m"a[n,t]"\033[0m";printf a[n,t]" "};m=c[n-1,m];print ""}print "max="s[1,1]}' ep18
# for min
$ awk '{for(n=0;n++<NF;)s[NR,n]=a[NR,n]=$n}END{c[0,0]=1;for(n=NR;n>1;n--)for(t=0;++t<n;)if(s[n,t]<s[n,t+1]){c[n-1,t]=t;s[n-1,t]+=s[n,t]}else{c[n-1,t]=t+1;s[n-1,t]+=s[n,t+1]};m=0;for(n=0;n++<NR;){for(p=NR-n;p-->0;)printf " ";for(t=0;t++<n;){if(c[n-1,m]==t)a[n,t]="\033[31m"a[n,t]"\033[0m";printf a[n,t]" "};m=c[n-1,m];print ""}print "min="s[1,1]}' ep18
|
|