Problem:
Multisect
We are developing the world's coolest AI robot product. After the long struggle, we finally managed to send our product at revision $R_{RC}$ to QA team as a release candidate. However, they reported that some tests failed! Because we were too lazy to set up a continuous integration system, we have no idea when our software corrupted. We only know that the software passed all the test at the past revision $R_{PASS}$. To determine the revision $R_{ENBUG}$ ($R_{PASS} < R_{ENBUG} \leq R_{RC}$) in which our software started to fail, we must test our product revision-by-revision.
Here, we can assume the following conditions:
When we test at the revision $R$, the test passes if $R < R_{ENBUG}$, or fails otherwise.
It is equally possible, which revision between $R_{PASS} + 1$ and $R_{RC}$ is $R_{ENBUG}$.
From the first assumption, we don't need to test all the revisions. All we have to do is to find the revision $R$ such that the test at $R - 1$ passes and the test at $R$ fails. We have $K$ testing devices. Using them, we can test at most $K$ different revisions simultaneously. We call this "parallel testing". By the restriction of the testing environment, we cannot start new tests until a current parallel testing finishes, even if we don't use all the $K$ devices.
Parallel testings take some cost. The more tests fail, the more costly the parallel testing becomes. If $i$ tests fail in a parallel testing, its cost is $T_i$ ($0 \leq i \leq K$). And if we run parallel testings multiple times, the total cost is the sum of their costs.
Of course we want to minimize the total cost to determine $R_{ENBUG}$, by choosing carefully how many and which revisions to test on each parallel testing. What is the minimum expected value of the total cost if we take an optimal strategy?
Input
The input consists of a single test case with the following format.
$R_{PASS}$ $R_{RC}$ $K$
$T_0$ $T_1$ ... $T_K$
$R_{PASS}$ and $R_{RC}$ are integers that represent the revision numbers of our software at which the test passed and failed, respectively. $1 \leq R_{PASS} < R_{RC} \leq 1,000$ holds. $K$ ($1 \leq K \leq 30$) is the maximum number of revisions we can test in a single parallel testing. $T_i$ is an integer that represents the cost of a parallel testing in which $i$ tests fail ($0 \leq i \leq K$). You can assume $1 \leq T_0 \leq T_1 \leq ... \leq T_K \leq 100,000$.
Output
Output the minimum expected value of the total cost. The output should not contain an error greater than 0.0001.
Sample Input 1
1 10 2
1 1 1
Output for the Sample Input 1
2.0
Sample Input 2
1 100 1
100 100
Output for the Sample Input 2
670.7070707
Sample Input 3
100 200 4
1 1 2 2 3
Output for the Sample Input 3
4.6400000
Sample Input 4
2 3 4
1 2 3 4 5
Output for the Sample Input 4
0.0
Sample Input 5
998 1000 4
10 100 1000 10000 100000
Output for the Sample Input 5
55.0

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds; //new version c++
//using namespace pb_ds;

#define PB push_back
#define MP make_pair
#define SZ size()
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ITR(i, j, n) for(int i = (j); i < (n); i++)
#define mem(array, val) memset(array, val, sizeof(array))
#define READ(filename) freopen(filename, "r", stdin)
#define WRITE(filename) freopen(filename, "w", stdout)
#define Fr first
#define Sc second
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define sd(a) scanf("%lf", &a)
#define ss(a) scanf("%s", a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define sdd(a, b) scanf("%lf%lf", &a, &b)
#define debug(x) cout << #x << ": " << x << endl
#define Fast_IO ios_base::sync_with_stdio(0);cin.tie(0)

typedef long long Long;
typedef pair <int, int> Pii;
///<-------------------------------------------------END OF TEMPLATE-------------------------------------------------->

#define MAX 1005
#define MAXG 35
int K, T[MAXG];
double dp[MAX][MAXG];

int main() {
   int rp, rc, N;
   sii(rp, rc); si(K);
   REP(i, K+1) si(T[i]);

   N = rc - rp;
   dp[1][1] = T[0];
   ITR(n, 2, N+1) {
      dp[n][1] = 1e12;

      ITR(k, 2, K+2) {
         if(k > n) break;
         dp[n][k] = 1e12;
         ITR(sz, 1, n) {
            if(n-sz < k-1) break;
            dp[n][k] = min(dp[n][k], (double(sz) / double(n)) * (dp[sz][1] - T[0] + T[k-1]) + (double(n - sz) / double(n)) * dp[n-sz][k-1]);
         }
         dp[n][1] = min(dp[n][1], dp[n][k]);
      }
      dp[n][1] += T[0];
      //printf("DP[%d]: %.8lf\n", n, DP[n]);
   }

   printf("%.8lf\n", dp[N][1] - T[0]);
   return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3840
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> ppi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)
#define RREP(i,n) RFOR(i,0,n)
#define sz(A) ((ll)A.size())
#define ALL(A) A.begin(),A.end()
#define LB(A,x) (lower_bound(ALL(A),x)-A.begin())
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
struct segtree{
    vi tree;
    int n;
    ll op(ll a,ll b){return max(a,b);}
    ll e(){return -1e18;}
    segtree(int _N){
        n=1;
        while(n<_N)n<<=1;
        tree.assign(2*n,e());
    }
    void set(int i,ll x){
        i+=n;
        tree[i]=x;
        while(i>1){
            i>>=1;
            tree[i]=op(tree[2*i],tree[2*i+1]);
        }
    }
    ll prod(int l,int r){
        l+=n;r+=n;
        ll L=e(),R=e();
        while(l<r){
            if(l%2)L=op(L,tree[l++]);
            if(r%2)R=op(tree[--r],R);
            l>>=1;r>>=1;
        }
        return op(L,R);
    }
};
int main(){
    ll a,b,K;cin>>a>>b>>K;
    vi T(K+1);
    REP(i,K+1)cin>>T[i];
    vector<vector<ld>>DP(1000,vector<ld>(K+2,1e18));
    REP(i,K+2)DP[0][i]=0;
    DP[1][K+1]=0;
    FOR(D,1,1000){
        RREP(_D,D)RREP(j,K+1){
            DP[D][j+1]=min(DP[D][j+1],DP[_D][j]+T[K-j]*(D-_D)+DP[D-_D][K+1]);
        }
    }
    //FOR(i,1,10){
        //for(auto j:DP[i])cout<<j<<" ";cout<<endl;
    //}
    printf("%.20Lf\n",DP[b-a][K+1]/(b-a));
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4028
final_rank: 12

code_snippet: #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

typedef double D;

int main() {
	int pass = ri();
	int rc = ri();
	
	int n = rc - pass;
	int k = ri();
	std::vector<int> t(k + 1);
	for (auto &i : t) i = ri();
	
	std::vector<D> res(n + 1, 1e18);
	std::vector<std::vector<D> > dp(k + 2, std::vector<D>(n + 1, 1e18));
	
	res[0] = res[1] = 0;
	dp[1][1] = t[0];
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= k + 1; j++) {
			for (int l = 1; l < i; l++) {
				dp[j][i] = std::min(dp[j][i], dp[j - 1][l] + (i - l) * (res[i - l] + t[j - 1]));
			}
		}
		
		double tmp = 1e18;
		for (int j = 1; j <= k + 1; j++) tmp = std::min(tmp, dp[j][i]);
		res[i] = tmp / i;
		
		dp[1][i] = std::min(dp[1][i], tmp + (double) t[0] * i);
	}
	printf("%.11f\n", res[n]);
	
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3664
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
using ll = long long;
template<class T> bool chmin(T &a,const T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a,const T b){if(a<b){a=b;return 1;}return 0;}
const int INF = (1<<30)-1;
#define all(p) p.begin(),p.end()
const int mod=998244353;

int main(){
	int A,B,K;
	cin>>A>>B>>K;
	vector<double> T(K+1);
	rep(i,0,K+1) cin>>T[i];
	int N=B-A;
	vector<vector<double>> dp(N+1,vector<double>(K+2,INF));
	rep(i,0,K+2) dp[0][i]=0;
	dp[1][0]=0;
	rep(i,1,N+1){
		rep(j,0,N-i+1) rep(k,1,K+2){
			//if(i==1) cout<<j<<" "<<k<<" "<<dp[2][0]<<endl;
			chmin(dp[i+j][k-1],dp[j][k]+dp[i][0]+T[k-1]*i);
		}
		//cout<<i<<" : "<<fixed<<setprecision(20)<<dp[i][0]/(double)(i)<<"\n";
	}
	cout<<fixed<<setprecision(20)<<dp[N][0]/(double)(N)<<"\n";
}
accuracy: 1
time_ms: 10
memory_kb: 3856
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back

const double INF = 9e18;
double dp[1005], dp2[55][1005];
double cst[55];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int l, r, k;
    cin >> l >> r >> k;
    r -= l;
    for (int i = 0; i <= k; ++i)
        cin >> cst[i];
    for (int j = 0; j <= k + 1; ++j)
        fill(dp2[j] + 1, dp2[j] + r + 1, INF);
    for (int i = 2; i <= r; ++i) {
        for (int j = k; j >= 0; --j)
            for (int p = 1; p <= r; ++p)
                dp2[j][p] = min(dp2[j][p], dp2[j + 1][p - (i - 1)] + (double)(i - 1) * (dp[i - 1] + cst[j]));
        dp[i] = INF;
        dp[i] = min(dp[i], dp2[0][i] / i);
    }
    cout << fixed << setprecision(7) << dp[r] << "\n";
}
accuracy: 1
time_ms: 10
memory_kb: 3560
final_rank: 2

code_snippet: /**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using int128_t = __int128_t;
#define repa(i, n) for(int i = 0; i < n; ++ i)
#define repb(i, a, b) for(int i = a; i < b; ++ i)
#define repc(i, a, b, c) for(int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define rep(...) overload4(__VA_ARGS__, repc, repb, repa)(__VA_ARGS__)
#define rep1a(i, n) for(int i = 0; i <= n; ++ i)
#define rep1b(i, a, b) for(int i = a; i <= b; ++ i)
#define rep1c(i, a, b, c) for(int i = a; i <= b; i += c)
#define rep1(...) overload4(__VA_ARGS__, rep1c, rep1b, rep1a)(__VA_ARGS__)
#define rev_repa(i, n) for(int i=n-1;i>=0;i--)
#define rev_repb(i, a, b) assert(a > b);for(int i=a;i>b;i--)
#define rev_rep(...) overload3(__VA_ARGS__, rev_repb, rev_repa)(__VA_ARGS__)
#define rev_rep1a(i, n) for(int i=n;i>=1;i--)
#define rev_rep1b(i, a, b) assert(a >= b);for(int i=a;i>=b;i--)
#define rev_rep1(...) overload3(__VA_ARGS__, rev_rep1b, rev_rep1a)(__VA_ARGS__)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define si(c) (int)(c).size()
inline ll popcnt(ull a){ return __builtin_popcountll(a); }
#define kth_bit(x, k) ((x>>k)&1)
#define unless(A) if(!(A))
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll intpow(ll a, ll b, ll m) {ll ans = 1; while(b){ if(b & 1) (ans *= a) %= m; (a *= a) %= m; b /= 2; } return ans; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
template <class T> using vvvc = vector<vvc<T>>;
template <class T> using vvvvc = vector<vvvc<T>>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template<class T> void scan(T& a){ cin >> a; }
template<class T> void scan(vector<T>& a){ for(auto&& i : a) scan(i); }
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){ scan(head); in(tail...); }
void print(){ cout << ' '; }
template<class T> void print(const T& a){ cout << a; }
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout << ' '; print(*i); } }
int out(){ cout << '\n'; return 0; }
template<class T> int out(const T& t){ print(t); cout << '\n'; return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); cout << ' '; out(tail...); return 0; }
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#define dump(...) { print(#__VA_ARGS__); print(":"); out(__VA_ARGS__); }
#else
#define debug(...)
#define dump(...)
#endif

struct io_setup {
    io_setup(int precision = 20) {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout << fixed << setprecision(precision);
    }
} io_setup_ {};

const int inf = 1e9 + 7;

void solve() {
    INT(r_pass, r_rc, k);
    VEC(int, t, k + 1);
    int n = r_rc - r_pass;
    if(n == 1) {
        out(0.0);
        return;
    }
    vvc<ld> dp(n + 1, vc<ld>(k + 1, inf));
    vc<ld> sum(n + 1, inf);
    for(int j = 1; j <= k; ++ j) {
        dp[1][j] = 0.0;
    }
    sum[0] = 0.0; sum[1] = 0.0;
    for(int i = 2; i <= n; ++ i) {
        for(int j = 1; j <= k; ++ j) {
            for(int p = 1; p <= i - j; ++ p) {
                ld res = 0.0;
                if(j != 1) res = (ld)(i - p) * (dp[i - p][j - 1]) / (ld)i + (ld)p * ((ld)t[j] + sum[p]) / (ld)i;
                else res = (ld)(i - p) * ((ld)t[0] + sum[i - p]) / (ld)i + (ld)p * ((ld)t[j] + sum[p]) / (ld)i;
                debug(i, j, p, res);
                chmin(dp[i][j], res);
            }
            debug(i, j, dp[i][j]);
            // sum[i] += dp[i][j];
            chmin(sum[i], dp[i][j]);
        }
    }
    ld ans = inf;
    for(int j = 1; j <= k; ++ j) {
        chmin(ans, dp[n][j]);
    }
    out(ans);
}

signed main() {
    int testcase = 1;
    // in(testcase);
    while(testcase--) solve();
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3820
final_rank: 11

code_snippet: /**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using int128_t = __int128_t;
#define repa(i, n) for(int i = 0; i < n; ++ i)
#define repb(i, a, b) for(int i = a; i < b; ++ i)
#define repc(i, a, b, c) for(int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define rep(...) overload4(__VA_ARGS__, repc, repb, repa)(__VA_ARGS__)
#define rep1a(i, n) for(int i = 0; i <= n; ++ i)
#define rep1b(i, a, b) for(int i = a; i <= b; ++ i)
#define rep1c(i, a, b, c) for(int i = a; i <= b; i += c)
#define rep1(...) overload4(__VA_ARGS__, rep1c, rep1b, rep1a)(__VA_ARGS__)
#define rev_repa(i, n) for(int i=n-1;i>=0;i--)
#define rev_repb(i, a, b) assert(a > b);for(int i=a;i>b;i--)
#define rev_rep(...) overload3(__VA_ARGS__, rev_repb, rev_repa)(__VA_ARGS__)
#define rev_rep1a(i, n) for(int i=n;i>=1;i--)
#define rev_rep1b(i, a, b) assert(a >= b);for(int i=a;i>=b;i--)
#define rev_rep1(...) overload3(__VA_ARGS__, rev_rep1b, rev_rep1a)(__VA_ARGS__)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define si(c) (int)(c).size()
inline ll popcnt(ull a){ return __builtin_popcountll(a); }
#define kth_bit(x, k) ((x>>k)&1)
#define unless(A) if(!(A))
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll intpow(ll a, ll b, ll m) {ll ans = 1; while(b){ if(b & 1) (ans *= a) %= m; (a *= a) %= m; b /= 2; } return ans; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
template <class T> using vvvc = vector<vvc<T>>;
template <class T> using vvvvc = vector<vvvc<T>>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template<class T> void scan(T& a){ cin >> a; }
template<class T> void scan(vector<T>& a){ for(auto&& i : a) scan(i); }
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){ scan(head); in(tail...); }
void print(){ cout << ' '; }
template<class T> void print(const T& a){ cout << a; }
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout << ' '; print(*i); } }
int out(){ cout << '\n'; return 0; }
template<class T> int out(const T& t){ print(t); cout << '\n'; return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); cout << ' '; out(tail...); return 0; }
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#define dump(...) { print(#__VA_ARGS__); print(":"); out(__VA_ARGS__); }
#else
#define debug(...)
#define dump(...)
#endif

struct io_setup {
    io_setup(int precision = 20) {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout << fixed << setprecision(precision);
    }
} io_setup_ {};

const int inf = 1e9 + 7;

void solve() {
    INT(r_pass, r_rc, k);
    VEC(int, t, k + 1);
    int n = r_rc - r_pass;
    if(n == 1) {
        out(0.0);
        return;
    }
    vvc<ld> dp(n + 1, vc<ld>(k + 1, inf));
    vc<ld> sum(n + 1, inf);
    for(int j = 1; j <= k; ++ j) {
        dp[1][j] = 0.0;
    }
    sum[0] = 0.0; sum[1] = 0.0;
    for(int i = 2; i <= n; ++ i) {
        for(int j = 1; j <= k; ++ j) {
            for(int p = 1; p <= i - 1; ++ p) {
                ld res = 0.0;
                if(j != 1) res = (ld)(i - p) / (ld)i * (dp[i - p][j - 1]) + (ld)p / (ld)i * (t[j] + sum[p]);
                else res = (ld)(i - p) / (ld)i * (t[0] + sum[i - p]) + (ld)p / (ld)i * (t[j] + sum[p]);
                debug(i, j, p, res);
                chmin(dp[i][j], res);
            }
            debug(i, j, dp[i][j]);
            // sum[i] += dp[i][j];
            chmin(sum[i], dp[i][j]);
        }
    }
    ld ans = inf;
    for(int j = 1; j <= k; ++ j) {
        chmin(ans, dp[n][j]);
    }
    out(ans);
}

signed main() {
    int testcase = 1;
    // in(testcase);
    while(testcase--) solve();
    return 0;
}
accuracy: 0.15384615384615385
time_ms: 40
memory_kb: 3580
final_rank: 17

code_snippet: /**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using int128_t = __int128_t;
#define repa(i, n) for(int i = 0; i < n; ++ i)
#define repb(i, a, b) for(int i = a; i < b; ++ i)
#define repc(i, a, b, c) for(int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define rep(...) overload4(__VA_ARGS__, repc, repb, repa)(__VA_ARGS__)
#define rep1a(i, n) for(int i = 0; i <= n; ++ i)
#define rep1b(i, a, b) for(int i = a; i <= b; ++ i)
#define rep1c(i, a, b, c) for(int i = a; i <= b; i += c)
#define rep1(...) overload4(__VA_ARGS__, rep1c, rep1b, rep1a)(__VA_ARGS__)
#define rev_repa(i, n) for(int i=n-1;i>=0;i--)
#define rev_repb(i, a, b) assert(a > b);for(int i=a;i>b;i--)
#define rev_rep(...) overload3(__VA_ARGS__, rev_repb, rev_repa)(__VA_ARGS__)
#define rev_rep1a(i, n) for(int i=n;i>=1;i--)
#define rev_rep1b(i, a, b) assert(a >= b);for(int i=a;i>=b;i--)
#define rev_rep1(...) overload3(__VA_ARGS__, rev_rep1b, rev_rep1a)(__VA_ARGS__)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))
#define si(c) (int)(c).size()
inline ll popcnt(ull a){ return __builtin_popcountll(a); }
#define kth_bit(x, k) ((x>>k)&1)
#define unless(A) if(!(A))
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll intpow(ll a, ll b, ll m) {ll ans = 1; while(b){ if(b & 1) (ans *= a) %= m; (a *= a) %= m; b /= 2; } return ans; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
template <class T> using vvvc = vector<vvc<T>>;
template <class T> using vvvvc = vector<vvvc<T>>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template<class T> void scan(T& a){ cin >> a; }
template<class T> void scan(vector<T>& a){ for(auto&& i : a) scan(i); }
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){ scan(head); in(tail...); }
void print(){ cout << ' '; }
template<class T> void print(const T& a){ cout << a; }
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout << ' '; print(*i); } }
int out(){ cout << '\n'; return 0; }
template<class T> int out(const T& t){ print(t); cout << '\n'; return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); cout << ' '; out(tail...); return 0; }
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#define dump(...) { print(#__VA_ARGS__); print(":"); out(__VA_ARGS__); }
#else
#define debug(...)
#define dump(...)
#endif

struct io_setup {
    io_setup(int precision = 20) {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout << fixed << setprecision(precision);
    }
} io_setup_ {};

const int inf = 1e9 + 7;

void solve() {
    INT(r_pass, r_rc, k);
    VEC(int, t, k + 1);
    int n = r_rc - r_pass;
    vvc<ld> dp(n + 1, vc<ld>(k + 1, inf));
    vc<ld> sum(n + 1, inf);
    for(int j = 1; j <= k; ++ j) {
        dp[1][j] = 0.0;
    }
    sum[0] = 0.0; sum[1] = 0.0;
    for(int i = 2; i <= n; ++ i) {
        for(int j = 1; j <= k; ++ j) {
            for(int p = 1; p <= i - 1; ++ p) {
                ld res = 0.0;
                if(j != 1) res = (ld)(i - p) / (ld)i * (dp[i - p][j - 1]) + (ld)p / (ld)i * (t[j] + sum[p]);
                else res = (ld)(i - p) / (ld)i * (t[0] + sum[i - p]) + (ld)p / (ld)i * (t[j] + sum[p]);
                debug(i, j, p, res);
                chmin(dp[i][j], res);
            }
            debug(i, j, dp[i][j]);
            // sum[i] += dp[i][j];
            chmin(sum[i], dp[i][j]);
        }
    }
    ld ans = inf;
    for(int j = 1; j <= k; ++ j) {
        chmin(ans, dp[n][j]);
    }
    out(ans);
}

signed main() {
    int testcase = 1;
    // in(testcase);
    while(testcase--) solve();
    return 0;
}
accuracy: 0.15384615384615385
time_ms: 40
memory_kb: 3568
final_rank: 16

code_snippet: #include <bits/stdc++.h>

#include <limits>
#include <type_traits>

namespace suisen {
// ! utility
template <typename ...Types>
using constraints_t = std::enable_if_t<std::conjunction_v<Types...>, std::nullptr_t>;
template <bool cond_v, typename Then, typename OrElse>
constexpr decltype(auto) constexpr_if(Then&& then, OrElse&& or_else) {
    if constexpr (cond_v) {
        return std::forward<Then>(then);
    } else {
        return std::forward<OrElse>(or_else);
    }
}

// ! function
template <typename ReturnType, typename Callable, typename ...Args>
using is_same_as_invoke_result = std::is_same<std::invoke_result_t<Callable, Args...>, ReturnType>;
template <typename F, typename T>
using is_uni_op = is_same_as_invoke_result<T, F, T>;
template <typename F, typename T>
using is_bin_op = is_same_as_invoke_result<T, F, T, T>;

template <typename Comparator, typename T>
using is_comparator = std::is_same<std::invoke_result_t<Comparator, T, T>, bool>;

// ! integral
template <typename T, typename = constraints_t<std::is_integral<T>>>
constexpr int bit_num = std::numeric_limits<std::make_unsigned_t<T>>::digits;
template <typename T, unsigned int n>
struct is_nbit { static constexpr bool value = bit_num<T> == n; };
template <typename T, unsigned int n>
static constexpr bool is_nbit_v = is_nbit<T, n>::value;

// ?
template <typename T>
struct safely_multipliable {};
template <>
struct safely_multipliable<int> { using type = long long; };
template <>
struct safely_multipliable<long long> { using type = __int128_t; };
template <>
struct safely_multipliable<unsigned int> { using type = unsigned long long; };
template <>
struct safely_multipliable<unsigned long int> { using type = __uint128_t; };
template <>
struct safely_multipliable<unsigned long long> { using type = __uint128_t; };
template <>
struct safely_multipliable<float> { using type = float; };
template <>
struct safely_multipliable<double> { using type = double; };
template <>
struct safely_multipliable<long double> { using type = long double; };
template <typename T>
using safely_multipliable_t = typename safely_multipliable<T>::type;

} // namespace suisen

// ! type aliases
using i128 = __int128_t;
using u128 = __uint128_t;

template <typename T>
using pq_greater = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <typename T, typename U>
using umap = std::unordered_map<T, U>;

// ! macros (capital: internal macro)
#define OVERLOAD2(_1,_2,name,...) name
#define OVERLOAD3(_1,_2,_3,name,...) name
#define OVERLOAD4(_1,_2,_3,_4,name,...) name

#define REP4(i,l,r,s)  for(std::remove_reference_t<std::remove_const_t<decltype(r)>>i=(l);i<(r);i+=(s))
#define REP3(i,l,r)    REP4(i,l,r,1)
#define REP2(i,n)      REP3(i,0,n)
#define REPINF3(i,l,s) for(std::remove_reference_t<std::remove_const_t<decltype(l)>>i=(l);;i+=(s))
#define REPINF2(i,l)   REPINF3(i,l,1)
#define REPINF1(i)     REPINF2(i,0)
#define RREP4(i,l,r,s) for(std::remove_reference_t<std::remove_const_t<decltype(r)>>i=(l)+fld((r)-(l)-1,s)*(s);i>=(l);i-=(s))
#define RREP3(i,l,r)   RREP4(i,l,r,1)
#define RREP2(i,n)     RREP3(i,0,n)

#define rep(...)    OVERLOAD4(__VA_ARGS__, REP4   , REP3   , REP2   )(__VA_ARGS__)
#define rrep(...)   OVERLOAD4(__VA_ARGS__, RREP4  , RREP3  , RREP2  )(__VA_ARGS__)
#define repinf(...) OVERLOAD3(__VA_ARGS__, REPINF3, REPINF2, REPINF1)(__VA_ARGS__)

#define CAT_I(a, b) a##b
#define CAT(a, b) CAT_I(a, b)
#define UNIQVAR(tag) CAT(tag, __LINE__)
#define loop(n) for (std::remove_reference_t<std::remove_const_t<decltype(n)>> UNIQVAR(loop_variable) = n; UNIQVAR(loop_variable) --> 0;)

#define all(iterable) std::begin(iterable), std::end(iterable)
#define input(type, ...) type __VA_ARGS__; read(__VA_ARGS__)

#ifdef LOCAL
#  define debug(...) debug_internal(#__VA_ARGS__, __VA_ARGS__)

template <class T, class... Args>
void debug_internal(const char* s, T&& first, Args&&... args) {
    constexpr const char* prefix = "[\033[32mDEBUG\033[m] ";
    constexpr const char* open_brakets = sizeof...(args) == 0 ? "" : "(";
    constexpr const char* close_brakets = sizeof...(args) == 0 ? "" : ")";
    std::cerr << prefix << open_brakets << s << close_brakets << ": " << open_brakets << std::forward<T>(first);
    ((std::cerr << ", " << std::forward<Args>(args)), ...);
    std::cerr << close_brakets << "\n";
}

#else
#  define debug(...) void(0)
#endif

// ! I/O utilities

// pair
template <typename T, typename U>
std::ostream& operator<<(std::ostream& out, const std::pair<T, U> &a) {
    return out << a.first << ' ' << a.second;
}
// tuple
template <unsigned int N = 0, typename ...Args>
std::ostream& operator<<(std::ostream& out, const std::tuple<Args...> &a) {
    if constexpr (N >= std::tuple_size_v<std::tuple<Args...>>) {
        return out;
    } else {
        out << std::get<N>(a);
        if constexpr (N + 1 < std::tuple_size_v<std::tuple<Args...>>) {
            out << ' ';
        }
        return operator<<<N + 1>(out, a);
    }
}
// vector
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T> &a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << ' ';
    }
    return out;
}
// array
template <typename T, size_t N>
std::ostream& operator<<(std::ostream& out, const std::array<T, N> &a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << ' ';
    }
    return out;
}
inline void print() { std::cout << '\n'; }
template <typename Head, typename... Tail>
inline void print(const Head &head, const Tail &...tails) {
    std::cout << head;
    if (sizeof...(tails)) std::cout << ' ';
    print(tails...);
}
template <typename Iterable>
auto print_all(const Iterable& v, std::string sep = " ", std::string end = "\n") -> decltype(std::cout << *v.begin(), void()) {
    for (auto it = v.begin(); it != v.end();) {
        std::cout << *it;
        if (++it != v.end()) std::cout << sep;
    }
    std::cout << end;
}

// pair
template <typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U> &a) {
    return in >> a.first >> a.second;
}
// tuple
template <unsigned int N = 0, typename ...Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...> &a) {
    if constexpr (N >= std::tuple_size_v<std::tuple<Args...>>) {
        return in;
    } else {
        return operator>><N + 1>(in >> std::get<N>(a), a);
    }
}
// vector
template <typename T>
std::istream& operator>>(std::istream& in, std::vector<T> &a) {
    for (auto it = a.begin(); it != a.end(); ++it) in >> *it;
    return in;
}
// array
template <typename T, size_t N>
std::istream& operator>>(std::istream& in, std::array<T, N> &a) {
    for (auto it = a.begin(); it != a.end(); ++it) in >> *it;
    return in;
}
template <typename ...Args>
void read(Args &...args) {
    ( std::cin >> ... >> args );
}

// ! integral utilities

// Returns pow(-1, n)
template <typename T>
constexpr inline int pow_m1(T n) {
    return -(n & 1) | 1;
}
// Returns pow(-1, n)
template <>
constexpr inline int pow_m1<bool>(bool n) {
    return -int(n) | 1;
}

// Returns floor(x / y)
template <typename T>
constexpr inline T fld(const T x, const T y) {
    return (x ^ y) >= 0 ? x / y : (x - (y + pow_m1(y >= 0))) / y;
}
template <typename T>
constexpr inline T cld(const T x, const T y) {
    return (x ^ y) <= 0 ? x / y : (x + (y + pow_m1(y >= 0))) / y;
}

template <typename T, suisen::constraints_t<suisen::is_nbit<T, 16>> = nullptr>
constexpr inline int popcount(const T x) { return __builtin_popcount(x); }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 32>> = nullptr>
constexpr inline int popcount(const T x) { return __builtin_popcount(x); }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 64>> = nullptr>
constexpr inline int popcount(const T x) { return __builtin_popcountll(x); }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 16>> = nullptr>
constexpr inline int count_lz(const T x) { return x ? __builtin_clz(x)   : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 32>> = nullptr>
constexpr inline int count_lz(const T x) { return x ? __builtin_clz(x)   : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 64>> = nullptr>
constexpr inline int count_lz(const T x) { return x ? __builtin_clzll(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 16>> = nullptr>
constexpr inline int count_tz(const T x) { return x ? __builtin_ctz(x)   : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 32>> = nullptr>
constexpr inline int count_tz(const T x) { return x ? __builtin_ctz(x)   : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 64>> = nullptr>
constexpr inline int count_tz(const T x) { return x ? __builtin_ctzll(x) : suisen::bit_num<T>; }
template <typename T>
constexpr inline int floor_log2(const T x) { return suisen::bit_num<T> - 1 - count_lz(x); }
template <typename T>
constexpr inline int ceil_log2(const T x)  { return floor_log2(x) + ((x & -x) != x); }
template <typename T>
constexpr inline int kth_bit(const T x, const unsigned int k) { return (x >> k) & 1; }
template <typename T>
constexpr inline int parity(const T x) { return popcount(x) & 1; }

struct all_subset {
    struct all_subset_iter {
        const int s; int t;
        constexpr all_subset_iter(int s) : s(s), t(s + 1) {}
        constexpr auto operator*() const { return t; }
        constexpr auto operator++() {}
        constexpr auto operator!=(std::nullptr_t) { return t ? (--t &= s, true) : false; }
    };
    int s;
    constexpr all_subset(int s) : s(s) {}
    constexpr auto begin() { return all_subset_iter(s); }
    constexpr auto end()   { return nullptr; }
};

// ! container

template <typename T, typename Comparator, suisen::constraints_t<suisen::is_comparator<Comparator, T>> = nullptr>
auto priqueue_comp(const Comparator comparator) {
    return std::priority_queue<T, std::vector<T>, Comparator>(comparator);
}

template <typename Iterable>
auto isize(const Iterable &iterable) -> decltype(int(iterable.size())) {
    return iterable.size();
}

template <typename T, typename Gen, suisen::constraints_t<suisen::is_same_as_invoke_result<T, Gen, int>> = nullptr>
auto generate_vector(int n, Gen generator) {
    std::vector<T> v(n);
    for (int i = 0; i < n; ++i) v[i] = generator(i);
    return v;
}
template <typename T>
auto generate_range_vector(T l, T r) {
    return generate_vector(r - l, [l](int i) { return l + i; });
}
template <typename T>
auto generate_range_vector(T n) {
    return generate_range_vector(0, n);
}

template <typename T>
void sort_unique_erase(std::vector<T> &a) {
    std::sort(a.begin(), a.end());
    a.erase(std::unique(a.begin(), a.end()), a.end());
}

template <typename InputIterator, typename BiConsumer>
auto foreach_adjacent_values(InputIterator first, InputIterator last, BiConsumer f) -> decltype(f(*first++, *last), void()) {
    if (first != last) for (auto itr = first, itl = itr++; itr != last; itl = itr++) f(*itl, *itr);
}
template <typename Container, typename BiConsumer>
auto foreach_adjacent_values(Container c, BiConsumer f) -> decltype(c.begin(), c.end(), void()){
    foreach_adjacent_values(c.begin(), c.end(), f);
}

// ! other utilities

// x <- min(x, y). returns true iff `x` has chenged.
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (y >= x) return false;
    x = y;
    return true;
}
// x <- max(x, y). returns true iff `x` has chenged.
template <typename T>
inline bool chmax(T &x, const T &y) {
    if (y <= x) return false;
    x = y;
    return true;
}

namespace suisen {}
using namespace suisen;
using namespace std;

struct io_setup {
    io_setup(int precision = 20) {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(precision);
    }
} io_setup_ {};

// ! code from here

constexpr long long inf = numeric_limits<long long>::max() / 2;

int main() {
    input(int, l, r, k);
    const int n = r - l;

    vector<long long> t(k + 1);
    read(t);

    vector<vector<long long>> dp(n + 1, vector<long long>(k + 1, inf));
    vector<long long> dp_min(n + 1, inf);
    dp[1][0] = dp_min[1] = 0;

    rep(i, 2, n + 1) {
        rep(x0, 1, i) {
            int x1 = i - x0;
            chmin(dp[i][1], x0 * t[1] + dp_min[x0] + x1 * t[0] + dp_min[x1]);
            chmin(dp_min[i], dp[i][1]);
        }
        rep(j, 2, k + 1) {
            rep(x, 1, i) {
                chmin(dp[i][j], dp[i - x][j - 1] + x * t[j] + dp_min[x]);
            }
            chmin(dp_min[i], dp[i][j]);
        }
        
    }

    print((double) dp_min[n] / n);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3720
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=1005;
const ll INF=1LL<<60;
double dp[MAX];
double cost[MAX][33];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A,B,K;cin>>A>>B>>K;
    int N=B-A;
    vector<double> C(K+1);
    for(int i=0;i<=K;i++) cin>>C[i];
    
    for(int t=2;t<=N;t++){
        for(int i=0;i<MAX;i++) for(int j=0;j<33;j++) cost[i][j]=INF;
        cost[t][0]=0;
        for(int i=t;i>=1;i--){
            for(int j=0;j<=K;j++){
                if(cost[i][j]==INF) continue;
                int need=(i+K-j)/(K+1-j);
                for(int k=need;k<=i;k++){
                    int to=i-k;
                    if(i==t&&to==0) continue;
                    if(to<0) continue;
                    chmin(cost[to][j+1],cost[i][j]+(double)(i-to)/t*(C[j]+dp[i-to]));
                }
            }
        }
        dp[t]=INF;
        for(int j=1;j<=K+1;j++) chmin(dp[t],cost[0][j]);
    }
    
    cout<<fixed<<setprecision(25)<<dp[N]<<endl;
}
accuracy: 1
time_ms: 1800
memory_kb: 3900
final_rank: 15

code_snippet: //#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

ld dp[1005][35];
ld ans[1005];
void solve() {
	int a, b, m; cin >> a >> b >> m;
	int n = b - a;
	vector<int> cost(m + 1);
	rep(i, m + 1)cin >> cost[i];
	rep(i, n + 1)rep(j, m+2)dp[i][j] = INF;
	rep(i, n + 1)ans[i] = INF;
	ans[0] = 0;
	ans[1] = 0;
	dp[0][0] = 0;
	for (int len = 1; len <= n; len++) {
		rep(c, m+1) {
			for (int ad = 1; ad < len; ad++) {
				ld val = dp[len - ad][c] + ad * cost[c] + ad*ans[ad];
				dp[len][c + 1] = min(dp[len][c + 1], val);
			}
		}
		rep(c, m + 2)ans[len] = min(ans[len], dp[len][c]/len);
		rep(c, m + 1) {
			for (int ad = len; ad <= len; ad++) {
				ld val = dp[len - ad][c] + ad * cost[c] + ad * ans[ad];
				dp[len][c + 1] = min(dp[len][c + 1], val);
			}
		}
	}
	//cout << dp[3][1] << "\n";
	//cout << ans[1] << "\n";
	cout << ans[n] << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(8);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4072
final_rank: 13

code_snippet: #include <bits/stdc++.h>
#define maxn 100086

using namespace std;

int l, r, n, m;
int t[maxn];
double f[maxn][40], g[maxn];

int main(){
	scanf("%d%d%d", &l, &r, &m);
	for(int i = 0;i <= m;i++) scanf("%d", &t[i]);
	n = r - l;
	f[1][0] = t[0], g[1] = 0;
	for(int i = 1;i <= m;i++) f[1][i] = 1e18;
	for(int i = 2;i <= n;i++){
		g[i] = 1e18;
		for(int j = 1;j <= m;j++){
			f[i][j] = 1e18;
			for(int k = 1;k < i;k++){
				f[i][j] = min(f[i][j], f[i - k][j - 1] + k * (g[k] + t[j])); 	
			}
			g[i] = min(g[i], f[i][j] / i);
		}
		f[i][0] = i * (g[i] + t[0]);
	}
	printf("%.10f", g[n]);
}
accuracy: 1
time_ms: 20
memory_kb: 3532
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
int r_pass,r_rc,k;
int n;
int a[55];
double dp[1005][35];

int main()
{
    cin>>r_pass>>r_rc>>k;
    n=r_rc-r_pass;
    for (int i=0;i<=k;i++)
    {
        cin>>a[i];
    }
    for (int i=2;i<=1000;i++)
    {
        for (int j=0;j<=k;j++)
        {
            dp[i][j]=1e10;
        }
    }
    for (int i=2;i<=n;i++)
    {
        for (int j=1;j<=k;j++)
        {
            for (int u=1;u<i;u++)
            {
                dp[i][j]=min(dp[i][j],1.0*u/i*(dp[u][j-1]+(j==1)*a[0])+1.0*(i-u)/i*(dp[i-u][0]+a[j]));
            }
        }
        for (int j=1;j<k;j++)
        {
            dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
        }
        dp[i][0]=dp[i][k];
    }
    printf("%.6f\n",dp[n][k]);
    return 0;
}
accuracy: 0.15384615384615385
time_ms: 100
memory_kb: 3476
final_rank: 18

code_snippet: #include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <set>
#ifdef XLor
  #define dbg(args...) cout << "" << #args << " -> ", err(args)
  void err() { std::cout << "" << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
using ll = long long;
using PII = pair<int,int>;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 2000 + 5;

int n, k, a[maxn];
double f[maxn][maxn], g[maxn];

int main() {
  int rp, rc;
  scanf("%d%d%d", &rp, &rc, &k);
  n = rc - rp;
  for (int i = 0; i <= k; i++) {
    scanf("%d", a + i);
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= k; j++) {
      f[i][j] = 1e18;
    }
  }
  f[1][0] = g[1] = 0.0;
  f[1][1] = a[1];
  for (int i = 2; i <= n; i++) {
    for (int k = 1; k < i; k++) {
      double cur = 1.0 * (i - k) / i * (g[i - k] + a[0]) + 1.0 * k / i * (g[k] + a[1]);
      f[i][1] = min(f[i][1], cur);
    }
    g[i] = f[i][1];
    for (int j = 2; j <= k; j++) {
      for (int k = 1; k < i; k++) {
        double cur = 1.0 * (i - k) / i * f[i - k][j - 1];
        cur += 1.0 * k / i * (a[j] + g[k]);
        f[i][j] = min(f[i][j], cur);
      }
      // dbg(i, j, f[i][j]);
      g[i] = min(g[i], f[i][j]);
    }
    // dbg(i, g[i]);
  }
  printf("%.8lf\n", g[n]);
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 7448
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N,K;
double T[33];
double dp[1011][33];
double minc[1011];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  {
    int r1,r2;
    cin>>r1>>r2;
    N=r2-r1;
  }
  cin>>K;
  rep(i,K+1)cin>>T[i];

  rep(i,N+1)repl(j,1,K+1)dp[i][j]=INF;
  rep(i,N+1)minc[i]=INF;
  minc[0]=0; minc[1]=0;
  repl(i,2,N+1){
    repl(j,1,K+1){
      repl(k,1,i){
        int l=i-k;
        double p1=(double)l/(double)i;
        double p2=(double)(i-l)/(double)i;
        if(j>1){
          minch(dp[i][j],p2*dp[k][j-1]+p1*(T[j]+minc[l]));
        }else{
          minch(dp[i][j],p2*(minc[i-l]+T[0])+p1*(T[j]+minc[l]));
        }
      }
      minch(minc[i],dp[i][j]);
    }
  }
  printf("%.10f\n", minc[N]);
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 3528
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

double dp[1001];
int a,b,k;
int t[35];
int sum[35];
double ct[35];
double dp2[1001][35];

double solve(int sz);
double solve2(int sz,int i);

double solve2(int sz,int i){
	if(dp2[sz][i]>=0.0)return dp2[sz][i];
	if(sz<=0){
		return 1e18;
	}
	if(i==0)return t[0]*sz+solve(sz)*sz;
	double ans=1e18;
	for(int j=1;j<=sz-1;j++){
		double val=solve(j)*j;
		val+=t[i]*j;
		val+=solve2(sz-j,i-1);
		ans=min(ans,val);
	}
	return dp2[sz][i]=ans;
}

double solve(int sz){
	if(dp[sz]>=0.0)return dp[sz];
	if(sz<=1)return 0;
	double ans=1e18;
	for(int i=1;i<=min(k,sz-1);i++){
		ans=min((double)solve2(sz,i)/sz,ans);
	}
	return (dp[sz]=ans);
}

int main(void){
	scanf("%d%d%d",&a,&b,&k);
	int n=b-a;
	for(int i=0;i<=k;i++){
		scanf("%d",&t[i]);
	}
	for(int i=0;i<=k;i++){
		sum[i+1]+=sum[i];
		sum[i+1]+=t[i];
		ct[i+1]=(double)sum[i+1]/(i+1);
	}
	for(int i=0;i<=n+1;i++){
		dp[i]=-1.0;
		for(int j=0;j<=k+1;j++){
			dp2[i][j]=-1;
		}
	}
	printf("%.10f\n",solve(n));
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3700
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

double dp[1001];
int a,b,k;
int t[35];
int sum[35];
double ct[35];
double dp2[1001][35];

double solve(int sz);
double solve2(int sz,int i);

double solve2(int sz,int i){
	if(dp2[sz][i]>=0.0)return dp2[sz][i];
	if(sz<=0){
		return 1e18;
	}
	if(i==0)return t[0]*sz+solve(sz)*sz;
	double ans=1e18;
	for(int j=1;j<=sz-1;j++){
		double val=solve(j)*j;
		val+=t[i]*j;
		val+=solve2(sz-j,i-1);
		ans=min(ans,val);
	}
	//printf("solve2 %d %d %f\n",sz,i,ans);
	return dp2[sz][i]=ans;
}

double solve(int sz){
	if(dp[sz]>=0.0)return dp[sz];
	if(sz<=1)return 0;
	//printf("%d\n",sz);
	double ans=1e18;
	for(int i=1;i<=min(k,sz-1);i++){
		/*
		double val=0;
		int v1=sz%(i+1);
		int v2=i+1-v1;
		int len=sz/(i+1);
		printf("%d %d %d\n",v1,v2,len);
		for(int j=0;j<v2;j++){
			val+=(double)t[j]*len/(sz);
		}
		for(int j=v2;j<=i;j++){
			val+=(double)t[j]*(len+1)/(sz);
		}
		val+=(double)solve(len)*(v2*len)/(sz);
		if(v1>0)val+=(double)solve(len+1)*(sz-v2*len)/(sz);
		*/
		ans=min((double)solve2(sz,i)/sz,ans);
	}
	//printf("%d %.2f\n",sz,ans);
	return (dp[sz]=ans);
}

int main(void){
	scanf("%d%d%d",&a,&b,&k);
	int n=b-a;
	for(int i=0;i<=k;i++){
		scanf("%d",&t[i]);
	}
	for(int i=0;i<=k;i++){
		sum[i+1]+=sum[i];
		sum[i+1]+=t[i];
		ct[i+1]=(double)sum[i+1]/(i+1);
		//printf("%.5f\n",ct[i+1]);
	}
	for(int i=0;i<=n+1;i++){
		dp[i]=-1.0;
		for(int j=0;j<=k+1;j++){
			dp2[i][j]=-1;
		}
	}
	printf("%.10f\n",solve(n));
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3720
final_rank: 8

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1005
#define SIZE 31

int R_OK,R_FALSE,K;
double cost[SIZE];
double dp[SIZE][NUM];
double memo[NUM];


double recursive(int length){

	if(memo[length] != DBL_MAX){
		return memo[length];
	}

	for(int x = 1; x <= min(K,length); x++){

		if(x == 1){

			for(int start = 1; start <= length-1; start++){

				dp[x][length] = min(dp[x][length],(double)start/(double)length*(recursive(start)+cost[1])+
						(double)(length-start)/(double)length*(recursive(length-start)+cost[0]));
			}

		}else{

			for(int start = 1; start <= length-x; start++){

				dp[x][length] = min(dp[x][length],(double)start/(double)length*(recursive(start)+cost[x])+
						(double)(length-start)/(double)length*dp[x-1][length-start]);
			}
		}
		memo[length] = min(memo[length],dp[x][length]);
	}

	return memo[length];
}

int main(){

	scanf("%d %d %d",&R_OK,&R_FALSE,&K);

	int max_index = R_FALSE-R_OK;

	for(int i = 0; i <= K; i++){
		scanf("%lf",&cost[i]);
	}

	for(int i = 0; i <= min(K,max_index); i++){
		for(int k = 0; k <= max_index; k++){
 			dp[i][k] = DBL_MAX;
		}
	}

	for(int i = 0; i <= max_index; i++)memo[i] = DBL_MAX;

	memo[0] = 0;
	memo[1] = 0;
	memo[2] = (cost[0]+cost[1])/2.0;
	dp[1][2] = memo[2];

	printf("%.10lf\n",recursive(max_index));

	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 3556
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 10;
const int K = 31;
const long double inf = 1e18;

long double f[N][K], g[N], t[K];

inline void chkmin(long double &a, long double b) {
	if (a > b) a = b;
}

int main() {
	int a, b;	scanf("%d%d", &a, &b);
	int K;		scanf("%d", &K);
	int n = b - a;
	for (int i = 0; i <= K; i++) {
		double x; scanf("%lf", &x);
		t[i] = x;
	}
	for (int i = 2; i <= n; i++) {
		f[i][1] = inf;
		for (int j = 1; j < i; j++) {
			int a = j, b = i - j;
			chkmin(f[i][1], a * (g[a] + t[1]) / i + b * (g[b] + t[0]) / i);
		}
		g[i] = f[i][1];
		for (int k = 2; k <= K; k++) {
			f[i][k] = inf;
			for (int j = 0; j <= i; j++) if (f[b][k-1] < inf){
				int a = j;
				int b = i - j;
				chkmin(f[i][k], a * (g[a] + t[k]) / i + f[b][k-1] * b / i);
			}
			chkmin(g[i], f[i][k]);
		}
	}
	printf("%.10lf\n", (double)g[n]);
	return 0;
}
/*
1 100 1
100 100
*/
accuracy: 0.15384615384615385
time_ms: 130
memory_kb: 3720
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 10;
const int K = 31;
const long double inf = 1e18;

long double f[N][K], g[N], t[K];

inline void chkmin(long double &a, long double b) {
	if (a > b) a = b;
}

int main() {
	int a, b;	scanf("%d%d", &a, &b);
	int K;		scanf("%d", &K);
	int n = b - a;
	for (int i = 0; i <= K; i++) {
		double x; scanf("%lf", &x);
		t[i] = x;
	}
	for (int i = 2; i <= n; i++) {
		f[i][1] = inf;
		for (int j = 1; j < i; j++) {
			int a = j, b = i - j;
			chkmin(f[i][1], a * (g[a] + t[1]) / i + b * (g[b] + t[0]) / i);
		}
		g[i] = f[i][1];
		for (int k = 2; k <= K; k++) {
			f[i][k] = inf;
			for (int j = 1; j < i; j++) if (f[b][k-1] < inf){
				int a = j;
				int b = i - j;
				chkmin(f[i][k], a * (g[a] + t[k]) / i + f[b][k-1] * b / i);
			}
			chkmin(g[i], f[i][k]);
		}
	}
	printf("%.10lf\n", (double)g[n]);
	return 0;
}
accuracy: 0.15384615384615385
time_ms: 140
memory_kb: 3720
final_rank: 20