题意:
给定n(n<=60)个直线 ,长度<=1000;
可以转化为取 计算 ans = (sum + 10 - g) / ( n + 1) 在小于5的条件下的最大值,其中sum为任取n个的直线长度和,g是给定常数。
思路:
用类似背包的求法,把可能取到的结果用dp[i][j] = 1表示,其中i表示容量,j表示取了几个。
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert> using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = ;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
/*-----------------------showtime----------------------*/ const int maxn = ;
int dp[maxn][];
int a[];
int main(){
int n,g;
scanf("%d%d", &n, &g);
for(int i=; i<=n; i++) scanf("%d", &a[i]);
dp[][] = ;
for(int i=; i<=n; i++){
for(int j=n; j>=; j--){
for(int k = maxn-; k>=a[i]; k--){
dp[k][j] |= dp[k-a[i]][j-];
}
}
}
double ans = -;
for(int k = g - ; k < maxn; k++){
for(int j=; j<=n; j++){
if(dp[k][j] == ) continue;
// cout<<k << " " << j<<endl;
double tmp = (k + - g)*1.0 / (j+1.0);
if(tmp <= 5.0) ans = max(ans, tmp);
}
}
if(ans < ) puts("impossible");
else printf("%.7f\n", ans);
return ;
}