# 【C++算法基础】#2暴力枚举的方法论与优化技巧 - 大力出奇迹

🎈 作者：Eriktse
🎈 简介：19岁，211计算机在读，CCPC全国赛金牌，ICPC区域赛银牌退役选手🏆力争以通俗易懂的方式讲解编程和算法！❤️欢迎关注我，一起交流C++/Python算法。（优质好文持续更新中……）🚀
🎈欢迎加群一起玩耍~QQ群：600240150

## 例题

### ETOJ 1014: straax'aks Array

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll N = 1e6 + 9, inf = 8e18;
ll a[N];

bool check(ll a, ll b, ll c, ll m)
{
return (a + b + c) * (a ^ b ^ c) >= m;
}

void solve()
{
int n, m;cin >> n >> m;
for(int i = 1;i <= n; ++ i)cin >> a[i];

ll ans = 0;
for(int i = 1;i <= n; ++ i)
for(int j = i + 1;j <= n; ++ j)
for(int k = j + 1;k <= n; ++ k)
if(check(a[i], a[j], a[k], m))
{
ans ++;
//cout << a[i] << ' ' << a[j] << ' ' << a[k] << '\n';
}

cout << ans << '\n';
}

signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while(_ --)solve();
return 0;
}

### ETOJ 1016: 全排列

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll N = 20, inf = 8e18;

ll a[N];
bitset<N> vis;

void dfs(ll dep, ll n)
{
if(dep == n + 1)
{
for(ll i = 1;i <= n; ++ i)cout << a[i] << " \n"[i == n];
return;
}

for(ll i = 1;i <= n; ++ i)
{
if(vis[i])continue;
vis[i] = true;
a[dep] = i;
dfs(dep + 1, n);
vis[i] = false;
}
}

void solve()
{
ll n;cin >> n;
dfs(1, n);
}

signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
while(_ --)solve();
return 0;
}

##### Eriktse
4 声望0 粉丝

19岁，性别未知，ACM-ICPC现役选手，ICPC亚洲区域赛银牌摆烂人，CCPC某省赛铜牌蒟蒻，武汉某院校计算机科学与技术专业本科在读。

0 条评论