163 条题解
-
0peterBBS LV 3 @ 2007-09-18 22:44:17
这么老的题!!!!!!!!1
-
02007-09-20 22:49:53@
40 2
9999999999999999999999999999999999999999如果这样呢.......
-
-22017-02-09 19:27:50@
高精算法
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct longnum{
int len;
int data[100];
longnum(){
memset(data,0,sizeof(data));
len=1;
}
longnum(char s[]){
len=strlen(s);
for(int i=1;i<=len;i++){
data[i]=s[len-i]-48;
}
}
longnum(int a){
int x=0;
while(a){
data[++x]=a%10;
a/=10;
}
len=x;
}
void out(){
// while(len>1&&data[len]==0) len--;
for(int i=len;i>=1;i--) printf("%d",data[i]);
}};
longnum operator==(longnum a,longnum b){
longnum c;if(a.len==b.len){
for(int i=1;i<=a.len;i++){
if(a.data[i]!=b.data[i]) c=0;
}
}
c=1;
return c;
}
longnum operator*(longnum a,longnum b){
longnum t;
int x=0;
t.len=a.len+b.len-1;
for(int i=1;i<=a.len;i++){
x=0;
for(int j=1;j<=b.len;j++){
t.data[i+j-1]=x+a.data[i]*b.data[j]+t.data[i+j-1];
x=t.data[i+j-1]/10;
t.data[i+j-1]%=10;
}
if(i!=a.len&&x>0) t.data[b.len+i]+=x;
} if(x>0){
t.len++;
t.data[t.len]+=x;
x=0;
}return t;
}
bool operator>(longnum a,longnum b){
if(a.len>b.len) return 1;
if(b.len>a.len) return 0;
for(int i=a.len;i>=1;i--){
if(a.data[i]>b.data[i])return 1;
if(a.data[i]<b.data[i])return 0;}
return 1;}
longnum max(longnum a,longnum b){
if( a>b) return a;
if( b>a) return b;
}
longnum f[42][10],dat[42][42];
int main(){
freopen("10071.in","r",stdin);
freopen("10071.out","w",stdout);
int n,k;
char s[44];
scanf("%d%d",&n,&k);
scanf("%s",&s[1]);for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
dat[j][i].len=i-j+1;
for(int k=1;k<=i-j+1;k++){
dat[j][i].data[k]=s[i-k+1]-'0';
}}
}
for(int i=1;i<=n;i++) f[i][0]=dat[1][i];
for(int i=1;i<=n;i++){
for(int j=1;j<=n-1;j++){for(int m=1;m<i-j+1&&m<i;m++){
f[i][j]=max(f[i][j],f[i-m][j-1]*dat[i-m+1][i]);}
}
}
f[n][k].out();return 0;
}