求助,91分

P1284 三角形牧场

```cpp #include <iostream> #include <cmath> using namespace std; #define endl '\n' #define maxn 50 int a[maxn],n,f[841][841]; double h=0,maxx=0; bool ff[845][845]={false}; double hl(int a,int b,int c,double h) { double p=sqrt(h*(h-a)*(h-b)*(h-c)); return p; } signed main(){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; h+=a[i]; } double zc=h/2.0; ff[0][0]=true; for(int k=0;k<n;k++) { for(int i=zc;i>=0;i--) { for(int j=i;j>=0;j--) { if(ff[i][j]==1) ff[i+a[k]][j]=true,ff[i][j+a[k]]=true; } } } for(int i=1;i<zc;i++) { for(int j=1;j<=i;j++) { if(ff[i][j]==true) { if((i+j)>(h-i-j)&&(i+h-i-j)>j&&(j+h-i-j)>i) { maxx=max(maxx,hl(i,j,h-i-j,zc)); } } } } if(maxx!=0) cout<<int (maxx*100); else cout<<"-1"; return 0; } ```
by Eden2026 @ 2023-07-16 11:05:00


看看吧我不是用的dfs
by Eden2026 @ 2023-07-16 11:05:27


|