Created
June 22, 2015 05:30
-
-
Save koosaga/b0c77bcca6f942af959d to your computer and use it in GitHub Desktop.
tdpcj.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <vector> | |
using namespace std; | |
double dp[1<<16]; | |
bool vis[1<<16]; | |
double f(int bit){ | |
if(bit == 0) return 0; | |
if(vis[bit]) return dp[bit]; | |
double ret = 1e9; | |
for (int i=0; i<16; i++) { | |
int cnt = 3; | |
double tmp = 0; | |
for (int j=-1; j<=1; j++) { | |
if(i + j == -1 || i + j >= 16) cnt--; | |
else if((bit >> (i+j)) & 1){ | |
tmp += f(bit ^ (1<<(i+j))); | |
} | |
else cnt--; | |
} | |
if(cnt == 0) continue; | |
ret = min(ret,(tmp + 3.0) / cnt); | |
} | |
vis[bit] = 1; | |
return dp[bit] = ret; | |
} | |
int main(){ | |
int t, u, b = 0; | |
scanf("%d",&t); | |
while (t--) { | |
scanf("%d",&u); | |
b |= (1<<u); | |
} | |
printf("%lf",f(b)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment