A:子序列的权值最小值:
A-子序列的权值最小值_牛客小白月赛63 (nowcoder.com)
#include<iostream>
using namespace std;
int n,m,ans[30];
int a[30];//待排列的数存储在此
bool vis[60];
int ans2 = 999999999;
void dfs(int d,int cnt)//按字典序输出n个数选m个数的所有组合
{
int ans1 = ans[0];
if(cnt==m)
{
for(int i=0;i<m-1;i++) {
ans1&=ans[i+1];
}
ans2 = min(ans1,ans2);
return ;
}
for(int i=d;i<n;i++)
{
ans[cnt]=a[i];
dfs(i+1,cnt+1);
}
}
int main()
{
cin>>n;
for (int i = 0; i < n; ++i) {
cin>>a[i];
}
for (int f = 1; f <= n; ++f) {
m = f;
fill(vis,vis+30,0);
dfs(0,0);
}
cout<<ans2<<endl;
return 0;
}
C:GCPC总决赛
C-GCPC总决赛_牛客小白月赛63 (nowcoder.com)
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+10;
int n;
int a[N],b[N];
int step[N];
int path[N];
int w = 0 ;
int l = 0 ;
int p = 0;
void dfs(int u){
if (u == n){
/*for (int i = 0; i < n; ++i) {
cout<<path[i]<<" ";
}*/
cout<<endl;
int w1 = 0 , l1 = 0;
for (int i = 0; i < n; ++i) {
if(path[i] > b[i])w1++;
else if(path[i] < b[i])l1++;
}
if(w1>l1){
w++;
}//a胜
else if(l1>w1){
l++;
}//b胜
else{
p++;
}//平局
}//搜到边界
for (int i = 0; i < n; ++i) {
if (!step[i]){
path[u] = a[i];
step[i] = true;
dfs(u+1);//搜下一步
step[i] = false;
}
}//搜n步
}
void solve()
{
cin>>n;
for (int i = 0; i < n; ++i) {
cin>>a[i];
}
sort(a,a+n);
for (int i = 0; i < n; ++i) {
cin>>b[i];
}
dfs(0);
cout<<w<<" "<<l<<" "<<p;
}
int main(){
solve();
}