ICode9

精准搜索请尝试: 精确搜索
  • AcWing 199. 余数之和2022-06-18 22:00:12

    题目传送门 零、参考资料 总结与思考:数论分块 【数学】数论分块(整除分块) 一、数论分块的相关概念 “数论分块”这个名词,其实比较模糊,没有一个广泛认同的严格定义。这里讲一下我个人的理解: 令\(\displaystyle f(i)=\lfloor \frac{n}{i} \rfloor\) \(f(i)\)的值,随着\(i\)的增加而单

  • AcWing杯 - 第56场周赛2022-06-18 21:01:05

    比赛链接 第 56 场周赛 先放代码,题解慢慢补 A AcWing 4482. 分组 #include<bits/stdc++.h> using namespace std; const int N=105; int n; int a[N]; int main() { cin>>n; int ans=0; for(int i=1;i<=n;i++) { int x; cin>>x;

  • AcWing 301. 任务安排22022-06-18 18:37:11

    题目链接 https://www.acwing.com/problem/content/303/ 题解 AC代码 import java.util.*; public class Main { static int N = (int) 3e5 + 10; static long[] sumT = new long[N], sumC = new long[N]; static long[] f = new long[N]; static int[] q = new

  • AcWing 300. 任务安排12022-06-18 17:02:52

    题目链接 https://www.acwing.com/problem/content/302/ 题解 AC代码 import java.util.*; public class Main { static int N = 5010; static int[] sumT = new int[N], sumC = new int[N]; static long[] f = new long[N]; static int n, s; public

  • [AcWing 1023] 买书2022-06-18 14:04:08

    点击查看代码 #include<iostream> using namespace std; const int N = 110, M = 10010; int m; int v[4] = {10, 20, 50, 100}; int f[M]; int main() { cin >> m; f[0] = 1; for (int i = 0; i < 4; i ++) for (int j = v[i]; j <= m; j ++) f[j]

  • [AcWing 278] 数字组合2022-06-18 13:33:17

    点击查看代码 #include<iostream> using namespace std; const int N = 110, M = 10010; int n, m; int a[N]; int f[M]; int main() { cin >> n >> m; for (int i = 1; i <= n; i ++) cin >> a[i]; f[0] = 1; for (int i = 1; i <= n; i ++)

  • [AcWing 1022] 宠物小精灵之收服2022-06-18 13:01:13

    点击查看代码 #include<iostream> using namespace std; const int N = 1010, M = 510; int V1, V2, n; int v1[N], v2[N]; int f[N][M]; int main() { cin >> V1 >> V2 >> n; for (int i = 1; i <= n; i ++) cin >> v1[i] >> v2[i];

  • [AcWing 272] 最长公共上升子序列2022-06-18 00:01:42

    点击查看代码 #include<iostream> using namespace std; const int N = 3010; int n; int a[N], b[N]; int f[N][N]; int main() { cin >> n; for (int i = 1; i <= n; i ++) cin >> a[i]; for (int i = 1; i <= n; i ++) cin >> b[i]; for (

  • [AcWing 1012] 友好城市2022-06-17 12:36:30

    点击查看代码 #include<iostream> #include<algorithm> #define fi first #define se second using namespace std; const int N = 5010; int n; int f[N]; pair<int,int> p[N]; int main() { cin >> n; for (int i = 1; i <= n; i ++) { int a

  • AcWing算法提高课 树形dp 树的中心2022-06-16 13:35:40

    AcWing 1073. 树的中心  #include<bits/stdc++.h> using namespace std; typedef long long LL; vector<int> adj[10010]; vector<int> w[10010]; int p[10010]; int wp[10010]; LL dis1[10010]; LL dis2[10010]; int next1[10010]; int next2[10010]; LL u

  • AcWing 214. Devu和鲜花2022-06-15 16:02:11

    题目传送门 \(Devu\) 有 \(N\) 个盒子,第 \(i\) 个盒子中有 \(A_i\) 枝花。 同一个盒子内的花颜色相同,不同盒子内的花颜色不同。 \(Devu\) 要从这些盒子中选出 \(M\) 枝花组成一束,求共有多少种方案。 若两束花每种颜色的花的数量都相同,则认为这两束花是相同的方案。 结果需对 10^9

  • [AcWing 125] 耍杂技的牛2022-06-14 22:34:12

    点击查看代码

  • AcWing 756. 蛇形矩阵2022-06-13 00:02:02

    #include <bits/stdc++.h> using namespace std; const int N = 110; int res[N][N], n, m, x, y, d = 0; int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; int main() { cin >> n >> m; for(int i = 1; i <= n*m; i++){ res[x][y] =

  • AcWing 1013. 机器分配(分组背包+求具体方案)2022-06-12 16:01:52

    题目链接 题目描述 总公司拥有M台 相同 的高效设备,准备分给下属的N个分公司。 各分公司若获得这些设备,可以为国家提供一定的盈利。盈利与分配的设备数量有关。 问:如何分配这M台设备才能使国家得到的盈利最大? 求出最大盈利值。 分配原则:每个公司有权获得任意数目的设备,但总台数不

  • AcWing 1317. 树屋阶梯2022-06-11 09:36:12

    题目传送门 一、题目分析 考虑以阶梯左下角那个点为第一个钢材的左下角,那么第一个钢材摆放情况便如下图(以 \(n = 5\) 为例) 对每种情况分别讨论,那么问题都被分成了两个子问题,设\(f[n]\)表示摆放高度为\(n\)的台阶的方法数,那么: \[\large f[5]=f[4]*f[0]+f[3]*f[1]+f[2]*f[2]+f[1]*f

  • AcWing 1307. 牡牛和牝牛2022-06-06 17:01:21

    题目传送门 一、算法分析 初始化:f[0] = 1(f[0]表示不摆放1的情况,初始值这么设,能让整个递推过程的边界是正确的则可行) 结果:f[0] + f[1] + f[2] + ... + f[n] 通过s[i]记录f[0] + ... + f[i]的前缀和可以优化到\(O(n)\) 二、朴素版本 #include <bits/stdc++.h> using namespace

  • AcWing 1020. 潜水员(二维费用的背包)2022-06-04 19:34:18

    题目链接 题目描述 潜水员为了潜水要使用特殊的装备。 他有一个带2种气体的气缸:一个为氧气,一个为氮气。 让潜水员下潜的深度需要各种数量的氧和氮。 潜水员有一定数量的气缸。 每个气缸都有重量和气体容量。 潜水员为了完成他的工作需要特定数量的氧和氮。 他完成工作所需气缸的

  • AcWing 1019. 庆功会(多重背包)2022-06-04 17:31:30

    题目链接 题目描述 为了庆贺班级在校运动会上取得全校第一名成绩,班主任决定开一场庆功会,为此拨款购买奖品犒劳运动员。 期望拨款金额能购买最大价值的奖品,可以补充他们的精力和体力。 题目模型 多重背包简单应用 题目代码 #include <iostream> using namespace std; const i

  • [AcWing 901] 滑雪2022-06-03 21:35:42

    记忆化搜索 点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 310; int n, m; int h[N][N]; int f[N][N]; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; int dp(int x, int y) { int &v = f[x][y]; if (v != -

  • [AcWing 285] 没有上司的舞会2022-06-03 13:04:07

    点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 6010; int n; int happy[N]; int h[N], e[N], ne[N], idx; bool has_father[N]; int f[N][2]; void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx ++;

  • AcWing 2003. 找到牛!2022-05-28 22:01:54

    题意 给定一个括号字符串,连续的两个'('可以表示牛的前脚,连续的两个')'可以表示牛的后脚,前脚必须在后脚的左侧,求牛的可能位置有几个,牛的可能位置由他的前后脚表示。 数据范围 \(1 \le N \le 50000\) 解题思路 正解是\(O(n)\)的做法,记一下当前位置及以前的"(("的对数,判断当前位置

  • AcWing 1912. 里程表2022-05-28 19:32:41

    题意 给定\(x\)和\(y(x \le y)\),计算满足大于等于\(x\)并且小于等于\(y\)的数的有趣数的个数。称一个数有趣当该数字满足: 除去前导零以外的所有数字中,除了一个数字不同以外,其他所有数字都是相同的,那么这个数就是“有趣的”。 例如,33323 和 110 是有趣的,而 9779 和 55555 不是有趣的

  • [AcWing 900] 整数划分2022-05-24 21:04:02

    类比完全背包 复杂度 \(O(n^{2})\) 总体复杂度 \(1000^{2} = 1 \times 10^{6}\) 点击查看代码 #include<iostream> using namespace std; const int N = 1010, mod = 1e9 + 7; int n; int f[N]; int main() { cin >> n; f[0] = 1; for (int i = 1; i <= n; i ++) f

  • [AcWing 899] 编辑距离2022-05-24 18:05:10

    复杂度 \(O(n \cdot m \cdot l^{2})\) 总体复杂度 $ 1000 \times 1000 \times 10^{2} = 1 \times 10^{8} $ 点击查看代码 #include<iostream> #include<cstring> using namespace std; const int N = 15, M = 1010; int n, m; char str[M][N]; int f[N][N]; int sol

  • AcWing 903. 昂贵的聘礼2022-05-22 21:04:38

    y总做法:建立一个虚拟原点,到所有物品的距离为物品原本价值,物品之间的价值为交易价值,枚举等级范围跑最短路即可 我的做法:以女儿为原点反向建图,物品之间的距离为交易价值,到每个物品的最短路加上这个物品的原本价值即为总花费,取最小 时间复杂度均为O(n^2*logn)(dij堆优化) #inclu

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有