壁とかパズルとか

パズルと将棋とボルダリングとダイビングが趣味です。

メモ

n個からk個取る組み合わせを全探索したいときメモ

bit全探索に慣れたい。 蟻本より、n個からk個取る組み合わせのJava版 public class Main { public static void main(String[] args){ int n = 4; int k = 2; int comb = (1<<k) -1; while(comb < 1 << n){ System.out.println(Integer.toString(comb,2)); int x = comb & -comb; int y = comb + x; comb = ( (comb & ~y) / x >> 1 ) | y; } } } /* 11 1…</k)>

優先度付きキューメモ

Javaで優先度付きキューを取り扱うときに毎回調べている気がする。メモする。 - PriorityQueue (Java Platform SE 8 ) Queue<Integer> que = new PriorityQueue<>(); que.add(3); que.add(1); que.add(4); que.add(1); que.add(5); while(!que.isEmpty()){ int i = qu</integer>…