0pts高精求助

P1018 [NOIP2000 提高组] 乘积最大

Markdown炸了 ```cpp #include<bits/stdc++.h> using namespace std; struct Int{ int len; short num[500]; int operator[](int a){ return num[a]; }void operator=(int a){ this->len=0; memset(this->num,0,sizeof(this->num)); while(a){ this->num[++this->len]=a%10; a/=10; } } }; Int operator+(Int a,Int b){ int m=0; if(a.len<b.len)swap(a,b); for(int i=1;i<=a.len;i++){ a.num[i]+=b[i]+m; m=a[i]/10;a.num[i]%=10; }if(m>0)a.num[++a.len]=m; return a; }Int operator*(Int a,Int b){ Int c;c.len=0;int m=0; memset(c.num,0,sizeof(c.num)); for(int i=1;i<=a.len;i++){ for(int j=1;j<=b.len;j++){ c.num[i+j-1]+=a[i]*b[j]; if(c[i+j-1])c.len=max(c.len,i+j-1); } }for(int i=1;i<=c.len;i++){ c.num[i]+=m;m=c[i]/10;c.num[i]%=10; }while(m){ c.num[++c.len]=m; m=c[c.len]/10; c.num[c.len]%=10; }return c; }Int operator+(Int a,int b){ Int c;c=b; return a+c; }Int operator*(Int a,int b){ Int c;c=b; return a*c; }bool operator<(Int a,Int b){ if(a.len!=b.len)return a.len<b.len; for(int i=a.len;i>0;i--){ if(a[i]!=b[i])return a[i]<b[i]; }return false; }bool operator==(Int a,Int b){ if(a.len!=b.len)return false; for(int i=1;i<=a.len;i++){ if(a[i]!=b[i])return false; }return true; }bool operator>(Int a,Int b){ if(a<b)return false; else if(a==b)return false; else return true; }bool operator<=(Int a,Int b){ return !(a>b); }bool operator>=(Int a,Int b){ return !(a<b); }istream &operator>>(istream &in,Int &a){ char l[500];cin>>l;a.len=strlen(l); memset(a.num,0,sizeof(a.num)); int al=a.len,ll=0; while(al>0&&ll<a.len){ a.num[al]=l[ll]-'0'; al--;ll++; }return in; }ostream &operator<<(ostream &out,Int a){ for(int i=a.len;i>0;i--){ cout<<a[i]; }return out; }Int max(Int a,Int b){ return a>b?a:b; }Int min(Int a,Int b){ return a<b?a:b; } Int dp[50][10],m[50][50];int a[50],n,k; int main(){ cin>>n>>k;getchar(); for(int i=1;i<=n;i++){ a[i]=getchar()-'0'; dp[i][1]=dp[i-1][1]*10+a[i]; }for(int i=1;i<=n;i++){ m[i][i]=a[i]; for(int j=i+1;j<=n;j++){ m[i][j]=m[i][j-1]*10+a[j]; } }for(int i=1;i<=n;i++){ for(int j=2;j<=k+1;j++){ if(i<j)break; for(int l=1;l<i;l++){ if(l<j-1)continue; dp[i][j]=max(dp[i][j],dp[l][j-1]*m[l+1][i]); } } }cout<<dp[n][k+1]; if(dp[n][k+1].len==0)cout<<0; return 0; } ```
by _cyh_ @ 2024-01-25 09:20:45


已AC,输入换一种写法就过了
by _cyh_ @ 2024-01-25 09:29:09


|