[蓝桥杯2016初赛]寒假作业-next_permutation枚举
生活随笔
收集整理的這篇文章主要介紹了
[蓝桥杯2016初赛]寒假作业-next_permutation枚举
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
暴搜代碼(耗時較長,要90s左右)如下:
#include <iostream> using namespace std; const int N = 15; int a[N]; bool st[N]; int cnt;void dfs(int u) {if (u == 13) {if (a[1] + a[2] == a[3] && a[4] - a[5] == a[6] && a[7]*a[8] == a[9] && a[11] * a[12] == a[10])cnt++;return ;}for (int i = 1; i <= 13; i++) {if (!st[i]) {a[u] = i;st[i] = true;dfs(u + 1);st[i] = false;a[u] = 0;}} }int main() {dfs(1);cout << cnt << endl;return 0; }總結
以上是生活随笔為你收集整理的[蓝桥杯2016初赛]寒假作业-next_permutation枚举的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [蓝桥杯2016初赛]搭积木-枚举,ne
- 下一篇: 怎样才能一天瘦一斤