ZOJ 1679 Telescope (DP)

利用重叠子问题,f [ i ][ j ][ k ] 表示 i 到j 的圆弧内的点 取 k 变形的最大面积。

#include <cstdio>
#include <algorithm> 
#include <cstring>
  
using namespace std;


// 规范相交
#include <cmath>

const double PI = 3.1415926535898; 


struct Point{
       double x, y;
       Point(double xx = 0.0, double yy = 0.0):x(xx), y(yy){} 
};
double det(double x1, double y1, double x2, double y2){
        return (x1 * y2) - (x2 * y1);
} 
inline double cross(Point a, Point b, Point c){
       return  det(b.x - a.x, b.y - a.y, c.x - a.x, c.y - a.y);
}

double f[50][50][50];
 
int main(){
   // freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout); 
    double p; 
    Point a[50];
    int n, m; 
    while (scanf("%d %d", &n, &m) == 2 && (n + m)){
          for (int i = 0; i < n; i++){
              scanf("%lf", &p);
              a[i] = Point(cos(p * 2 * PI), sin(p * 2 * PI));
          }
          memset(f, 0, sizeof(f)); 
          for (int k = 3; k <= m; k++){ 
                 for (int i = 0; i < n; i++){
                   for (int j = (i + 2) % n; j != i; j++, j %= n){
                       
                       for (int t = (i + 1)%n; t != j; t++, t %= n){
                           f[i][j][k] = max(f[i][t][k - 1] + cross(a[i], a[t], a[j]) / 2, f[i][j][k]);
                       }
                   }
                 }
          } 
          double ans = 0.0;
          for (int i = 0; i < n; i++){
                   for (int j = (i + 2) % n; j != i; j++, j %= n){
                       ans = max(ans, f[i][j][m]);
                   }
          } 
           
          printf("%.6f\n", ans);             
                    
    }
    return 0;
} 
        
     


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值