poj 1948 二维01背包
来源:互联网 发布:2010江苏高考数学知乎 编辑:程序博客网 时间:2024/06/05 06:55
dp[i][j]代表能否组成一边长为i和一边长为j的三角形,剩下的一边就是sum-i-j了
接下来就是背包的做法了
#include<stdio.h>#include<math.h>#include<string.h>bool dp[810][810];int get_area(int x,int y,int z){double p=(x+y+z)/2.0;return int(sqrt(p*(p-x)*(p-y)*(p-z))*100);}int max(int a,int b){return a>b?a:b;}int a[50];int main(){int n,i,j,k,sum=0; scanf("%d",&n);for(i=1;i<=n;i++) {scanf("%d",&a[i]);sum+=a[i];}int tmp=sum;sum/=2;sum++;memset(dp,false,sizeof(dp));dp[0][0]=true;for(i=1;i<=n;i++){for(j=sum;j>=0;j--){for(k=sum;k>=0;k--){if(j>=a[i]&&dp[j-a[i]][k]||k>=a[i]&&dp[j][k-a[i]])dp[j][k]=true;}}} int ans=-1;for(i=1;i<=sum;i++)for(j=1;j<=i;j++)if(dp[i][j]) ans=max(ans,get_area(i,j,tmp-i-j));printf("%d\n",ans);return 0;}
- poj 1948二维01背包
- poj 1948 二维01背包
- poj 1948 二维01背包
- poj 1948 二维背包
- poj 1948 Triangular Pastures(二维01背包)
- poj 1948 Triangular Pastures 二维01背包
- poj 1948 Triangular Pastures 二维01背包
- POJ -- 1948 二维背包问题
- poj 2576二维01背包
- poj 1948 Triangular Pastures (dp 二维01背包)
- 【POJ 1948】Triangular Pastures(dp—二维01背包)
- poj 1948 Triangular Pastures 二维背包
- POJ 1948 Triangular Pastures(二维背包)
- poj 2576 简单 二维背包
- poj 1837 Balance 二维背包
- poj 1948 Triangular Pastures(二维0/1背包)
- POJ 1948 Triangular Pastures 二维 0-1背包
- POJ 1948 (Triangular Pastures)二维背包 DP/DFS
- poj 3628 01背包
- poj 3211 01 背包
- poj 1745 dp
- 多校第一场
- poj 1837 01背包
- poj 1948 二维01背包
- poj 1976 dp
- hdu 1824 2-sat
- hdu 1203 01背包
- hdu 2955 Robberies 01背包
- hdu 3033 分组背包 每组至少选一个
- hdu 1712 分组背包 每组至多取一个背包
- poj 2723 2-sat
- poj 2536 二分匹配