National training Day1 solution to a problem
T1 divided
Meaning of the questions:
There \ (n-\) number \ (a_1, a_2, ..., a_n \) has a number m \ (B_1, B_2, ..., B_n \)
令\(a = a_1\times a_2\,\times ... \times \,a_n\)
令\(b = b_1\times\,b_2 \times\,...\,\times\,b_n\)
Analyzing \ (A \) whether \ (B \) multiple
Input: \ (n-, m \)
Output: \ (Yes / No \)
Practice: is a prime factorization of a simple
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n, m;
int a[1010], b[1010];
int p[3][20]={};
void divid(int op, int x)
{
if(x == 1) return;
if(x == 2) p[op][1]++;
if(x == 3) p[op][2]++;
if(x == 4) p[op][1] += 2;
if(x == 5) p[op][3]++;
if(x == 6) {p[op][1]++; p[op][2]++;}
return;
}
int main()
{
freopen("divide.in","r",stdin);
freopen("divide.out","w",stdout);
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
divid(1, a[i]);
}
for(int i = 1; i <= m; i++)
{
scanf("%d", &b[i]);
divid(2, b[i]);
}
for(int i = 1; i <= 3; i++)
{
if(p[1][i] >= p[2][i])continue;
else
{
printf("No\n"); return 0;
}
}
printf("Yes\n");
return 0;
}
/*
样例:
输入:2 3
6 6
1 3 4
输出:Yes
*/
T2 graph
Meaning of the questions:
To generate n now points a directed graph. Requirements are met:
1. If \ (a-> b \) side, there are (b-> a \) \ edge
2. If \ (a-> b \) sides and \ (b-> c \) side, there are \ (a-> c \) edge
3. At least one point no loopback
Find a few programs. May be larger as a result, the results of \ (m \) modulo
Input: \ (n-, m \)
Output: The answer
practice:
This question is the meaning of problems in addition to relatively pit outside, it does not have much difficulty. Note that, according to the meaning of the questions, if a point where the communication block size is greater than or equal to 2, the point must have a self-loop.
My approach is: Let \ (f [i] [0 ] \) represents \ (I \) points freely combined, and each point there are several solutions of loopback
\ (f [i] [1 ] \) represents \ (I \) points freely combined with at least \ (1 \) point of the program number without loopback
The method I transfer equation somewhat unique, I was watching \ (1 \) the number of points where the communication block of the dot were transferred to note that the transfer is to be discussed \ (1 \) No. point is isolated as a point If isolated, there are \ (1 \) dot from the ring, and two cases not looping, need to be discussed separately, the state transition equation is as follows:
\ (f [i] [1 ] + = f [i - 1] [1] \, \, \, \, 1 \) dots and isolated \ (1 \) exists dot loopback
\ (f [i] [1 ] + = f [i - 1] [1] + f [i - 1] [0] \, \, \, \, 1 \) dots isolated and \ (1 \) No. loopback point is not present, then the other point may loopback, loopback may not
\ (f [i] [1 ] + = \ sum_ {j = 2} ^ {i} f [i - j] [1] \ times C_ {i-1} ^ {j-1} \, \, \ , \, \) is calculated \ (1 \) communication block size number of point as \ (J \) number of scheme
\ (f [i] [0 ] + = f [i-1] [0] \, \, \, \, 1 \) can only be isolated from the loop when the number of points
\ (f [i] [0 ] + = \ sum_ {j = 2} ^ {i} f [i - j] [0] \ times C_ {i-1} ^ {j-1} \, \, \ , \, \) is calculated \ (1 \) communication block size number of point as \ (J \) number of scheme
Pascal's Triangle combination with a number on it.
Teacher practice is to "first \ (1 \) points" to "first \ (i \) points", in fact, the wording is the same, but the idea is different.
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define maxn 2010
#define ll long long
int n, mol;
ll f[maxn][2];// 1:符合题意 0:不符合题意
ll C[maxn][maxn];
int main()
{
freopen("graph.in", "r", stdin);
freopen("graph.out", "w", stdout);
scanf("%d%d", &n, &mol);
for(int i = 0; i <= n; i++) C[i][0] = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= i; j++)
{
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mol;
}
}
/* for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= i; j++)
printf("C[%d][%d] = %lld ", i, j, C[i][j]);
printf("\n");
}
*/
f[1][1] = 1; f[1][0] = 1;
for(int i = 2; i <= n; i++)
{
f[i][1] = (f[i][1] + f[i - 1][1] + f[i - 1][0] + f[i - 1][1]) % mol;
f[i][0] = (f[i][0] + f[i - 1][0]) % mol;
for(int j = 2; j < i; j++)
{
// f[i][1] = (f[i][1] + ( ( ( (C[i - 1][j - 1] * S[j - 1][j - 1]) % mol ) * ( (f[i - j][0] + f[i - j][1]) % mol) ) % mol)) % mol;
f[i][1] = (f[i][1] + (C[i - 1][j - 1] * f[i - j][1]) % mol) % mol;
f[i][0] = (f[i][0] + (C[i - 1][j - 1] * f[i - j][0]) % mol) % mol;
}
f[i][0] = (f[i][0] + 1) % mol;
}
// for(int i = 1; i <= n; i++)
// printf("f[%d][0] = %lld f[%d][1] = %lld\n", i, f[i][0], i, f[i][1]);
printf("%lld\n", f[n][1]);
return 0;
}
/*
样例:
输入:2 5
输出:3
*/