宁波优化网站哪家好,织梦网站地图怎么做,如何设置淘宝友情链接,要写网站建设方案个人主页#xff1a;GUIQU. 归属专栏#xff1a;每日一题 文章目录 1. 【2.3】P8784 [蓝桥杯 2022 省 B] 积木画2. 【2.4】P8656 [蓝桥杯 2017 国 B] 对局匹配3. 【2.5】[ABC365D] AtCoder Janken 34. 【2.6】P8703 [蓝桥杯 2019 国 B] 最优包含5. 【2.7】P8624 [蓝桥杯 2015… 个人主页GUIQU. 归属专栏每日一题 文章目录 1. 【2.3】P8784 [蓝桥杯 2022 省 B] 积木画2. 【2.4】P8656 [蓝桥杯 2017 国 B] 对局匹配3. 【2.5】[ABC365D] AtCoder Janken 34. 【2.6】P8703 [蓝桥杯 2019 国 B] 最优包含5. 【2.7】P8624 [蓝桥杯 2015 省 AB] 垒骰子6. 【2.8】P8774 [蓝桥杯 2022 省 A] 爬树的甲壳虫7. 【2.9】[ARC189C] Balls and Boxes 正文
1. 【2.3】P8784 [蓝桥杯 2022 省 B] 积木画 题目链接https://www.luogu.com.cn/problem/P8784 【AC_Code】
#include iostream
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;const int mod 1e9 7;
int N;int main()
{IOS; cin N;if (N 1){cout 1 \n;return 0;}if (N 2){cout 2 \n;return 0;}if (N 3){cout 5 \n;return 0;}int a 1, b 2, c 5, d;for (int i 4; i N; i ){d c * 2 % mod a;a b, b c, c d;a % mod, b % mod, c % mod, d % mod;}cout d \n;return 0;
}2. 【2.4】P8656 [蓝桥杯 2017 国 B] 对局匹配 题目链接https://www.luogu.com.cn/problem/P8656 【AC_Code】
#include iostream
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);using namespace std;const int maxN 1e5 10;
int N, K, index, ans, a[maxN];int main()
{IOS; cin N K;for (int i 0; i N; i ) cin index, a[index] ;if (K 0){for (int i 0; i N; i ) if (a[i]) ans ;cout ans \n;return 0;}for (int i 0; i maxN; i ){if (a[i] a[i K]) a[i K] - a[i];else a[i K] 0;}for (int i 0; i maxN - K; i ) ans a[i];cout ans \n;return 0;
}3. 【2.5】[ABC365D] AtCoder Janken 3 题目链接https://www.luogu.com.cn/problem/AT_abc365_d 【AC_Code】
#include bits/stdc.h
#define int long longusing namespace std;const int N 2e5 10;
int n, ans, f[N][10];
string s;int main()
{cin n s;if (s[0] R) {f[0][1] 0;f[0][2] 1;}if (s[0] P) {f[0][2] 0;f[0][3] 1;}if (s[0] S) {f[0][1] 1;f[0][3] 0;}for (int i 1; i n; i) {if (s[i] R) {f[i][1] max(f[i - 1][2], f[i - 1][3]);f[i][2] max(f[i - 1][1], f[i - 1][3]) 1;}if (s[i] P) {f[i][2] max(f[i - 1][1], f[i - 1][3]);f[i][3] max(f[i - 1][1], f[i - 1][2]) 1;}if (s[i] S) {f[i][1] max(f[i - 1][2], f[i - 1][3]) 1;f[i][3] max(f[i - 1][1], f[i - 1][2]);}}cout max({f[n - 1][1], f[n - 1][2], f[n - 1][3]});return 0;
}4. 【2.6】P8703 [蓝桥杯 2019 国 B] 最优包含 题目链接https://www.luogu.com.cn/problem/P8703 【AC_Code】
#include iostream
#include cstring
#include algorithm
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define inf 0x3f3f3f3fusing namespace std;const int maxn 1010;
int dp[maxn][maxn];
string S, T;int main()
{IOS; cin S T; S S, T T;memset(dp, inf, sizeof(dp));for (int i 0; i S.size() 1; i ) dp[i][0] 0;for (int i 1; i S.size(); i ) for (int j 1; j S.size(); j ){if (S[i] T[j]) dp[i][j] dp[i-1][j-1];else dp[i][j] min(dp[i-1][j-1]1, dp[i-1][j]);}cout dp[S.size()][T.size()] \n;return 0;
}5. 【2.7】P8624 [蓝桥杯 2015 省 AB] 垒骰子 题目链接https://www.luogu.com.cn/problem/P8624 【AC_Code】
#includebits/stdc.h
using namespace std;
#define rep(x,y,z) for(int xy;xz;x)
typedef long long LL;
const int mod1e97;
int n,m,a,b,oppo[7]{0,4,5,6,1,2,3};
bool st[7][7];
struct matrix{LL c[7][7];matrix(){memset(c,0,sizeof c);}
}A,res;
matrix operator * (matrix x,matrix y){matrix t;rep(i,1,6){rep(j,1,6){rep(k,1,6){t.c[i][j](t.c[i][j]x.c[i][k]*y.c[k][j])%mod;}}}return t;
}
void fastpow(LL k){rep(i,1,6) res.c[1][i]4;rep(i,1,6){rep(j,1,6){if(st[i][oppo[j]]) A.c[i][j]0;else A.c[i][j]4;}}while(k){if(k1) resres*A;AA*A;k1;}
}int main()
{cinnm;while(m--){cinab;st[a][b]st[b][a]1;}fastpow(n-1);LL ans0;rep(i,1,6) ans(ans%modres.c[1][i]%mod)%mod;coutans;return 0;
}6. 【2.8】P8774 [蓝桥杯 2022 省 A] 爬树的甲壳虫 题目链接https://www.luogu.com.cn/problem/P8774 【AC_Code】
#include bits/stdc.husing namespace std;const int N 1e5 5;
const int P 998244353;int n, a[N], b[N];int fp(int x, int y) {int res 1;for (; y; y 1) {if (y 1) {res (1ll * res * x) % P;}x (1ll * x * x) % P;}return res;
}int main() {scanf(%d, n);for (int i 1; i n; i) {scanf(%d%d, a[i], b[i]);}int s1 1, s2 0, s3 0;for (int i 1; i n; i) {int p1 (1ll * a[i] * fp(b[i], P - 2)) % P;int p2 (1ll * (b[i] - a[i]) * fp(b[i], P - 2)) % P;s3 (s3 s1) % P;s2 (s2 1ll * s1 * p1) % P;s1 (1ll * s1 * p2) % P;}printf(%d, (1ll * s3 * fp(1 - s2 P, P - 2)) % P);return 0;
}7. 【2.9】[ARC189C] Balls and Boxes 题目链接https://www.luogu.com.cn/problem/AT_arc189_c 【AC_Code】
#include bits/stdc.h#define F(i, a, b) for (int i (a); i (b); i)
#define dF(i, a, b) for (int i (a); i (b); --i)using namespace std;typedef long long LL;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pairint, int pii;const int N 2e5 5;int n, x, a[N], b[N], p[N], q[N];
int m, k, s[N], t[N], tt[N];
bool vis[N];int dp[N], c[N], ans;void Update(int x, int k) {while (x n) {c[x] max(c[x], k);x x -x;}
}void Query(int y, int x) {while (x) {y max(y, c[x]);x - x -x;}
}int main()
{ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);cin n x;F(i, 1, n) {cin a[i];}F(i, 1, n) {cin b[i];}F(i, 1, n) {cin p[i];}F(i, 1, n) {cin q[i];}int u p[x];bool now 0;vis[x] 1;while (!vis[u]) {now | a[u];vis[u] 1;if (now) {s[m] u;}u p[u];}F(i, 1, n) {if (!vis[i] a[i]) {return cout -1, 0;}}F(i, 1, n) {vis[i] 0;}u q[x];now 0;vis[x] 1;while (!vis[u]) {now | b[u];vis[u] 1;if (now) {t[k] u;}u q[u];}F(i, 1, n) {if (!vis[i] b[i]) {return cout -1, 0;}}F(i, 1, k) {tt[t[i]] i;}F(i, 1, m) {if (tt[s[i]]) {Query(dp[i], tt[s[i]]);Update(tt[s[i]], dp[i]);}}F(i, 1, n) {ans max(ans, dp[i]);}cout m k - ans;return 0;
}结语 感谢您的阅读期待您的一键三连欢迎指正