0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AtCoder】順列の全探索

Last updated at Posted at 2024-06-03

ポイント

  • next_permutation/prev_permutationを使う
  • do-while文を使う
  • 事前に配列をソートしておく
vector<int> arr = { 3, 1, 4, 7, 2 };

// 昇順探索
sort(arr.begin(), arr.end());
do {
  for (int x : arr) cout << x << " ";
  cout << endl;
} while (next_permutation(arr.begin(), arr.end()));

// 降順探索
sort(arr.rbegin(), arr.rend());
do {
  for (int x : arr) cout << x << " ";
  cout << endl;
} while (prev_permutation(arr.begin(), arr.end()));

例題:典型90問032 - AtCoder Ekiden(★3)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?