目录调整
This commit is contained in:
45
00lanqiao chap/test99-4-1-2.cpp
Normal file
45
00lanqiao chap/test99-4-1-2.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// lanqiao2942 数字王国之军训排队
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 15;
|
||||
int a[N], n;
|
||||
vector<int> v[N];
|
||||
|
||||
// 剪枝
|
||||
bool dfs(int cnt, int dep){
|
||||
if(dep == n+1){
|
||||
return true;
|
||||
}
|
||||
// 枚举每个人所属的队伍
|
||||
for(int i = 1; i <= cnt; i++){
|
||||
bool tag = true;
|
||||
for(const auto &j:v[i]){
|
||||
if(a[dep] % j == 0){
|
||||
tag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!tag) continue;
|
||||
v[i].push_back(a[dep]);
|
||||
if(dfs(cnt, dep + 1)) return true;
|
||||
// 恢复现场
|
||||
v[i].pop_back();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int main(){
|
||||
cin >> n;
|
||||
for(int i = 1; i <= n; i++) cin >> a[i];
|
||||
sort(a+1, a+1+n);
|
||||
for(int i = 1; i <= n; i++){
|
||||
if(dfs(i, 1)){
|
||||
cout << i << '\n';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* test samples
|
||||
4
|
||||
2 3 4 4
|
||||
*/
|
||||
Reference in New Issue
Block a user