Today is 2021.9.23, brushing two 1400 in the afternoon, div2 in the evening, and one after that.

## 1348.B. Phoenix and Beauty (construction)

### General idea:

Construct a sequence such that the elements of a subsequence of length k in the sequence always sum to m.

### Reflection:

If the sum of all the elements of a subsequence with length k in the sequence is m, then the subsequence must be abcd abcd abcd... (abcd length is k)

If the element type exceeds m, it cannot be constructed.

Because the length of the given sequence is not more than 100 and the length of the constructed sequence is not more than 10000, 100 sets of subsequences can be output.

The construction is m long and contains all kinds of subsequences.

### Code:

const int N = 200010; int T, n, m, a[N]; bool f[110]; int cnt; int main(){ Ios; cin>>T; while(T--) { cin>>n>>m; mem(f,0); cnt=0; for(int i=1;i<=n;i++) { int x;cin>>x; if(!f[x]) f[x]=1,a[++cnt]=x; } if(cnt>m){ cout<<-1<<"\n"; continue; } for(int i=cnt+1;i<=m;i++) a[i]=a[i-1]; cout<<100*m<<"\n"; for(int i=1;i<=100;i++){ for(int j=1;j<=m;j++){ cout<<a[j]<<" "; } } cout<<"\n"; } return 0; }

## 689.A. Vacations (dp)

### General idea:

There are at most two choices per day, but they cannot be the same for two consecutive days.

Q. How many days do I have a minimum rest?

### Reflection:

Idea 1:dfs

Direct brush search, super-strong pruning: 1.cnt exceeded ans exit; 2. recursion limit

Idea 2:dp

Two-dimensional dp, opens three states into one dimension.

For each point, find the source of the current state.

### Code:

const int N = 200010; int T, n, m, a[N]; int ans=1e9,cnt; int step,flag; int f[N][5]; void dfs(int u,int last) { step++; if(step>=10000000){ flag=1;return; } if(flag||cnt>=ans) return; if(u==n+1){ ans=min(ans,cnt); return; } if(a[u]==0){ cnt++; dfs(u+1,0); cnt--; } else if(a[u]==1) { if(last==1) cnt++,dfs(u+1,0),cnt--; else dfs(u+1,1); } else if(a[u]==2){ if(last==2) cnt++,dfs(u+1,0),cnt--; else dfs(u+1,2); } else{ if(last!=1) dfs(u+1,1); if(last!=2) dfs(u+1,2); } } void DP() { for(int i=1;i<=n;i++) f[i][0]=f[i][1]=f[i][2]=-1e9; for(int i=1;i<=n;i++) { f[i][0]=max(f[i-1][0],max(f[i-1][1],f[i-1][2])); if(a[i]==1||a[i]==3) f[i][1]=max(f[i-1][0],f[i-1][2])+1; if(a[i]==2||a[i]==3) f[i][2]=max(f[i-1][0],f[i-1][1])+1; } ans=n-max(f[n][0],max(f[n][1],f[n][2])); } int main(){ Ios; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; // dfs(1,0); DP(); cout<<ans; return 0; }

## 515.C. Drazil and Factorial (thinking)

### General idea:

Set to operation F(x) to represent the product of all its bit factorials. (x may have a leading 0)

Now given x, to find the maximum a, make F(a)=F(x), and each of a cannot be zero or one.

### Reflection:

To make a maximum, let x decompose by the most factors, which is to decompose the prime factor and then make a as long as possible.

Since recombinant a has a certain length, to maximize a, a large mass factor is first exported.

Because F(a)=F(x), when you output a value x, you need to have -1 of all the values from 2 to X.

### Code:

const int N = 200010; int T, n, m, a[N]; int f[10][10]={{0},{1},{2},{3},{2,2},{5},{3,2},{7},{2,2,2},{3,3}}; int t[10]={0,1,1,1,4,1,2,1,3,2}; int cnt[10]; int main(){ cin>>n; for(int i=1;i<=n;i++) { char c;cin>>c; int x=c-'0'; for(int j=2;j<=x;j++) { for(int k=0;k<t[j];k++) { cnt[f[j][k]]++; } } } for(int i=9;i>=2;i--) { while(cnt[i]) { for(int j=i;j>=2;j--) { for(int k=0;k<t[j];k++){ cnt[f[j][k]]--; } } cout<<i; } } return 0; }

# Codeforces Round #745 (Div. 2)

## A. CQXYM Count Permutations (number theory, thinking)

### General idea:

Given the number n, ask 2n how many sequences in the full permutation satisfy: a i < a i + 1 ai<ai+1 The number of ai<ai+1 is not less than n. n ≤ 1 e 5 n ≤1e5 n < 1e5, the answer is correct 1 e 9 + 7 1e9+7 1e9+7 modelling.

### Reflection:

At first glance, this question seems to have no idea. I think, this is question A?

Finally, it is clear what the author intended.

The key point is that the number of locations that meet the conditions is not less than n, which is a special breakthrough point.

If you add in the full permutation of 2n numbers, you can see that half of the total permutations of 2n numbers satisfy the conditions.

So this question is the requirement: 2n number of full permutations/ 2.

But there is one trick:

n is very large, to 1e5, if you multiply by an edge and divide by 2, it will be different from the original answer.

But since the answer is 123*...*2n and you divide 2 eventually, you get about a point in advance, you get about 2, you multiply it back from 3, you get the model by multiplying it. That's right.

### Code:

const int N = 200010, mod=1e9+7; int T, n, m, a[N]; int main(){ Ios; cin>>T; while(T--) { cin>>n; if(n==1){ cout<<1; cout<<"\n"; continue; } else if(n==2){ cout<<12; cout<<"\n"; continue; } ll ans=1; for(int i=3;i<=2*n;i++) { ans=ans*i%mod; } cout<<ans<<endl; } return 0; }

## B. Diameter of Graph (thinking)

### General idea:

Given n n n points and m edges, ask if an undirected connected graph can be constructed where the maximum value in the minimum distance between two points is less than k-1. (There are no multiple edges and self-rings)

### Reflection:

I just saw that I had no idea.

Start by analyzing m's range limitations:

Because it is a connected graph, m should not be less than n-1;

Since there are no self-rings and double edges, the maximum number of edges m is not more than
C
n
2
=
n
∗
(
n
−
1
)
/
2
C_n^2 = n*(n-1)/2
Cn2=n∗(n−1)/2.

So n-1 < m < n*(n-1)/2.

It is found that when m <[n-1, n*(n-1)/2), the maximum value in the minimum distance is 2;

When m = n*n(n-1)/2, which is the complete graph, the minimum distance is 1.

So, first judge if m is in range, then judge the size of k.

Note the case where the number of special judgements n is 1.

### Code:

const int N = 200010; int T, n, m, a[N]; int main(){ cin>>T; while(T--) { int k; cin>>n>>m>>k; if(n==1){ if(k>=2&&m==0) cout<<"yes\n"; else cout<<"no\n"; } else if(m<n-1||m>(ll)n*(n-1)/2) cout<<"no\n"; else if(k>=4) cout<<"yes\n"; else if(k==3){ if(m==(ll)n*(n-1)/2) cout<<"yes\n"; else cout<<"no\n"; } else cout<<"no\n"; } return 0; }

This is really a bit difficult.

You would have lost a lot if your teammates weren't on the shelf.