Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
也是DP,C++In Reply To:DP做法。 Posted by:The_Dawn at 2011-04-17 11:50:48 dp[l][s] : 以s开头长度为l的串有多少个 #include <cstdio> #include <cstring> char str[12]; int len; long long dp[27][27]; long long ans; void fill() { for( int s=1; s<=26; s++ ) dp[1][s] = 1; for( int l=2; l<=len; l++ ) for( int s=1; s<=27-l; s++ ) for( int i=s; i<=27-l; i++ ) dp[l][s] += dp[l-1][i+1]; } int main() { scanf( "%s", &(str[1]) ); len = strlen(&str[1]); for( int i=1; i<len; i++ ) if( str[i]>=str[i+1] ) { printf( "0\n" ); return 0; } fill(); for( int i=1; i<len; i++ ) for( int s=1; s<=27-i; s++ ) ans += dp[i][s]; for( int i=0; i<len; i++ ) for( int s= i==0?'a':str[i]+1 ; s<str[i+1]; s++ ) ans += dp[len-i][s-'a'+1]; printf( "%lld\n", ans+1 ); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator