示例#1
0
文件: C.cpp 项目: blmarket/icpc
void take2(int pos, bits &ret) {
    ret.set(pos);
    for(int i=0;i<N-1;i++) {
        if(rela[i].first == pos && !ret.test(rela[i].second)) {
            take2(rela[i].second, ret);
        }
        if(rela[i].second == pos && !ret.test(rela[i].first)) {
            take2(rela[i].first, ret);
        }
    }
}
示例#2
0
文件: C.cpp 项目: blmarket/icpc
int go(bits &st) {
    if(memo.count(st)) {
        return memo[st];
    }
    bits candi = st;

    int cnt = candi.count();
    if(cnt == 0) return 1;

    for(int i=0;i<N-1;i++) {
        int p1 = rela[i].first;
        int p2 = rela[i].second;
        if(!st.test(p1) || !st.test(p2)) continue;
        candi.reset(p2);
    }

    long long rett = 0;
    for(int i=0;i<N;i++) {
        if(candi.test(i)) {
            long long ret = 1;
            int cnt2 = cnt-1;
            for(int j=0;j<N-1;j++) {
                if(rela[j].first == i) {
                    bits tmp;
                    take(rela[j].second, i, tmp);
                    tmp.set(rela[j].second);
                    for(int k=0;k<N;k++) {
                        if(tmp.test(k) && !st.test(k))
                            tmp.reset(k);
                    }

                    int tmp2 = tmp.count();

                    ret *= combi[cnt2][tmp2];
                    cnt2 -= tmp2;
                    ret %= 1000000007;

                    ret *= go(tmp);
                    ret %= 1000000007;
                }
            }
            rett += ret;
            rett %= 1000000007;
        }
    }
    memo[st] = rett;
}
示例#3
0
static inline bool process(bits &was_processed, bits state, val const j,
                           val const rem, val const d,
                           char const *const actname, val const lhs, val const rhs) {
  if (was_processed.test(j))
    return false;
  was_processed.set(j);
  if (target.test(j)) {
    state.set(j);
    if (iddfs(state, j, rem - 1, d - 1)) {
      result[d].name = actname;
      result[d].lhs = lhs;
      result[d].rhs = rhs;
      return true;
    }
    return false;
  }
  action &defrd = deferred[d][defrd_size[d]];
  defrd.name = actname;
  defrd.lhs = lhs;
  defrd.rhs = rhs;
  defrd.res = j;
  ++defrd_size[d];
  return false;
}