2019牛客暑期多校训练营第二场
2019-07-26 / Luo Jinrong   

进度

A B C D E F G H I J

D. Kth Minimum Clique

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<bits/stdc++.h>
#define FIN freopen("./D.in","r",stdin)
#define debug(x) cout<<#x"=["<<x<<"]"<<endl
using namespace std;
typedef long long ll;
const int maxn(1e2+5);
const double pi=acos(-1);
ll n,k,w[maxn];
string e[maxn];
struct clique{//存储一个团
ll w;//当前团的权值
int num;//当前团内点数
vector<int> p;//当前团内各点
bool operator < (const clique &c) const {
return w>c.w;
}
}cli[maxn],qt;
priority_queue<clique> q;
int main(){
#ifndef ONLINE_JUDGE
FIN;
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>w[i];
cli[i].w=w[i];
cli[i].num=0;
cli[i].p.push_back(i);
q.push(cli[i]);
}
for(int i=1;i<=n;i++){
cin>>e[i];
}
k--;
if(k==0){
cout<<0<<endl;
return 0;
}
while(!q.empty()){
qt=q.top();
q.pop();
k--;
if(k==0){
cout<<qt.w<<endl;
return 0;
}
int now=qt.p[qt.num];
bool flag;
for(int i=now+1;i<=n;i++){
flag=1;
for(int j=0;j<=qt.num;j++){
if(e[qt.p[j]][i-1]=='0'){
flag=0;
break;
}
}
if(flag){
qt.num++;
qt.p.push_back(i);
qt.w+=w[i];
q.push(qt);
qt.num--;
qt.p.pop_back();
qt.w-=w[i];
}
}
}
cout<<-1<<endl;
}

F. Partition problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<bits/stdc++.h>
#define FIN freopen("./F.in","r",stdin)
#define debug(x) cout<<#x"=["<<x<<"]"<<endl
using namespace std;
typedef long long ll;
const ll maxn(1e2+5);
const double pi=acos(-1);
ll n,v[maxn][maxn],ans,num1,num2,s1[maxn],s2[maxn];
void dfs(ll index,ll sum){
if(num1==n&&num2==n){
ans=max(sum,ans);
}
if(num1<n){
ll k=0;
s1[++num1]=index;
for(ll i=1;i<=num2;i++){
k+=v[s1[num1]][s2[i]];
}
dfs(index+1,sum+k);
num1--;
}
if(num2<n){
ll k=0;
s2[++num2]=index;
for(ll i=1;i<=num1;i++){
k+=v[s2[num2]][s1[i]];
}
dfs(index+1,sum+k);
num2--;
}
}
int main(){
#ifndef ONLINE_JUDGE
FIN;
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(ll i=1;i<=n*2;i++){
for(ll j=1;j<=n*2;j++){
cin>>v[i][j];
}
}
dfs(1,0);
cout<<ans<<endl;
}

H. Second Large Rectangle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF(0x3f3f3f3f3f3f3f);
const double ESP(1e-9);
const ll mod(1e9+7);
#define per(i, a, b) for(int i=a; i<b; i++)
#define rep(i, a, b) for(int i=b-1; i>=a; i--)
#define mem(a, b) memset(a, b, sizeof(a))
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a%mod; a = a * a%mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

const int MAXN(1e3 + 7);
int n, m;
string str;
int high[MAXN];

int mxx, mxx2;
int stkhg[MAXN], stkpos[MAXN];
int cnt;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

cin >> n >> m;
high[m+1] = 0;
per(i, 1, n+1) {
cin >> str;
per(j, 1, m+1) {
high[j] = str[j-1]=='0'?0:high[j]+1;
}
stkhg[0] = stkpos[0] = cnt = 0;
per(j, 1, m+2) {
if(high[j]>stkhg[cnt]) {
stkhg[++cnt] = high[j];
stkpos[cnt] = j;
} else if(high[j]<stkhg[cnt]) {
while (high[j] < stkhg[cnt]) {
int area = (j - stkpos[cnt]) * stkhg[cnt];
if (area >= mxx) {
mxx2 = mxx;
mxx = area;
mxx2 = max(mxx2, max(area - stkhg[cnt], area - (j - stkpos[j])));
} else if (area > mxx2) {
mxx2 = area;
}
cnt--;
}
if(stkhg[cnt]!=high[j]) {
stkhg[++cnt] = high[j];
}
}
}
}

cout << mxx2 << endl;

return 0;
}

return 0;


本文链接:
https://luojinrong.github.io/2019/07/26/2019牛客暑期多校训练营第二场/