Problem:
Score : 100 points

Problem Statement

Given is an integer N.

Takahashi chooses an integer a from the positive integers not greater than N with equal probability.

Find the probability that a is odd.

Constraints

1 \leq N \leq 100

Input

Input is given from Standard Input in the following format:

N

Output

Print the probability that a is odd.
Your output will be considered correct when its absolute or relative error from the judge's output is at most 10^{-6}.

Sample Input 1

4

Sample Output 1

0.5000000000

There are four positive integers not greater than 4: 1, 2, 3, and 4. Among them, we have two odd numbers: 1 and 3. Thus, the answer is \frac{2}{4} = 0.5.

Sample Input 2

5

Sample Output 2

0.6000000000

Sample Input 3

1

Sample Output 3

1.0000000000

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

//author:emre yazicioglu

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define fori(a,b,c) for(ll a = b;a < ll(c); a++)
#define ford(a,b,c) for(ll a = b;a >= ll(c); a--)

const int INF = 1e9 + 7;
const int N = 2e6 + 7;
ll n, m, k, a[N], b[N], d, q, t;
ll sum, cur, cnt;
int p[1 << 12];
map <ll, ll> mp;
vector <ll> v;
string str;

int f(int cur, int mask, int cost) {
  if(mask == d)
    return cost;
  if(cur == m + 1)
    return INF;
  int rev, need = 0, ans = INF;
  rev = ((1 << n) - 1) ^ mask;
  for(int i = 0; i < n; i++)
    if((rev >> i) & 1)
      need += (1 << i);
  for(int i = 0; i <= need; i++)
    if(p[mask | i] != -1)
      ans = min(ans, p[mask | i]);
  int x, y;
  x = f(cur + 1, mask | b[cur], cost + a[cur]);
  y = f(cur + 1, mask, cost);
  return p[mask] = min({ans, x, y});
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);

  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  
  memset(p, -1, sizeof p);
  cin >> n >> m;
  d = (1 << n) - 1;
  for(int i = 1; i <= m; i++) {
    cin >> a[i] >> t;
    for(int j = 1; j <= t; j++){
      cin >> k;
      b[i] |= 1 << (k - 1);
    }
  }
  int ans = f(1, 0, 0);
  cout << (ans != INF ? ans : -1);
}