02 2020 档案

摘要:思路: 区间dp,定义的 l 是区间的长度。for(k)的循环时防止(()的类似情况 代码: #include<iostream> #include<stdio.h> #include<string.h> using namespace std; const int maxn = 101; int 阅读全文
posted @ 2020-02-27 21:18 sqsq 阅读(124) 评论(2) 推荐(0) 编辑
摘要:石子合并(每次合并相邻的两堆石子,代价为这两堆石子的重量和,把一排石子合并为一堆,求最小代价) 是一个经典的问题。dp可以做到O(n*n)的时间复杂度,方法是: 设f[i,j]为合并从i到j的石子所用最小代价。 f[i,j]=min(sum(i,j)+f[i,k]+f[k+1,j])对所有i<=k< 阅读全文
posted @ 2020-02-27 17:15 sqsq 阅读(760) 评论(0) 推荐(1) 编辑
摘要:代码: #include<iostream> #include<stdio.h> #include<string.h> using namespace std; const int maxn = 1005; int dp[maxn][maxn]; int main(){ char s1[maxn], 阅读全文
posted @ 2020-02-26 22:31 sqsq 阅读(106) 评论(0) 推荐(0) 编辑
摘要:代码: #include<iostream> #include<stdio.h> using namespace std; const int maxn = 1001; int a[maxn],dp[maxn]; int main(){ int n; cin>>n; for(int i=1;i<=n 阅读全文
posted @ 2020-02-26 17:49 sqsq 阅读(84) 评论(0) 推荐(0) 编辑
摘要:求C(n,m)%p; 概念: 组合数我们用C(n,m)表示,它代表在n个数中取m个数的方案。(这个概念主要用于将问题抽象到组合数上)。 公式: 1、C(n,m)=C(n,n-m); 2、C(n,m)=C(n-1,m-1)+C(n-1,m); 3、C(0,n)+C(1,n)+C(2,n)+C(3,n) 阅读全文
posted @ 2020-02-24 21:24 sqsq 阅读(824) 评论(0) 推荐(0) 编辑
摘要:注意: 有的时候memset会出问题 思路: i代表A,j代表B,题目要求n个AB,m个BA,所以在一个字符串中,前n个A贡献给AB中的A,前m个B贡献给BA中的B,这里用到贪心的思想 所以当i<=n时,直接用于贡献给AB中的A,当i>n时,i-n个A用来组成BA,因此当j>i-n时,此时可以放A组 阅读全文
posted @ 2020-02-23 23:34 sqsq 阅读(107) 评论(0) 推荐(0) 编辑
摘要:思想: 线性基和快速幂 代码: #include<iostream> #include<stdio.h> #include<cstring> #include<vector> using namespace std; typedef long long ll; const int mod = 1e9 阅读全文
posted @ 2020-02-22 15:49 sqsq 阅读(162) 评论(0) 推荐(0) 编辑
摘要:代码: 方法一: 这个是根据完全背包的思路来做,但是加了对个数的限制。 #include<iostream> #include<stdio.h> #include<string.h> using namespace std; const int maxn = 1e5+10; int dp[maxn] 阅读全文
posted @ 2020-02-21 14:54 sqsq 阅读(140) 评论(0) 推荐(0) 编辑
摘要:代码: #include<iostream> #include<stdio.h> using namespace std; typedef long long ll; const int inf = 0x3f3f3f; int main(){ int t; cin>>t; while(t--){ i 阅读全文
posted @ 2020-02-20 22:24 sqsq 阅读(134) 评论(0) 推荐(0) 编辑
摘要:代码: 错误代码:超空间:由于定义了一个二维的dp数组,然后超了,所以我们要把二维转换为一维 #include<iostream> #include<stdio.h> #include<string.h> using namespace std; const int maxn = 3500; int 阅读全文
posted @ 2020-02-20 17:55 sqsq 阅读(144) 评论(0) 推荐(0) 编辑
摘要:代码: #include<iostream> #include<stdio.h> using namespace std; typedef long long ll; int a[20]; ll dp[20][2]; //if6:当前为是否为6;limit:上一位是否是上界 ll dfs(int l 阅读全文
posted @ 2020-02-18 21:38 sqsq 阅读(90) 评论(0) 推荐(0) 编辑
摘要:F maki和tree 思路: 用到并查集的思想 如图: 简单路径上只有一个黑色点的方案:第一种端点有一个为黑色点,第二种两端点均为白色点,端点连接的线路中有一个黑色点 ans = (1+2+3)+1*2+2*3+1*3 = (1+2+3)+1*(2+3)+2*3 代码: #include<iost 阅读全文
posted @ 2020-02-17 23:13 sqsq 阅读(176) 评论(0) 推荐(0) 编辑
摘要:D 重排列 思路: upper_bound(a+1,a+1+n,b[i])-a-1记录的是在a[i]中第一个大于b[i]的地址, lower_bound(a+1,a+1+n,b[i])-a-1记录的是在a[i]中第一个不小于b[i]的地址 内部的思想是二分 a 1 1 2 3 b 1 2 3 4 c 阅读全文
posted @ 2020-02-16 12:19 sqsq 阅读(103) 评论(0) 推荐(0) 编辑
摘要:1.概念 求(a/b)%m时,因b可能会过大,会出现爆精度的情况,所以需变除法为乘法。若a*x≡1(mod b),且a与b互质,我们定义x是a的逆元,记为a^(-1)或inv(a)。 2.三种方法 2.1 费马小定理 #include<cstdio> #include<cstring> using 阅读全文
posted @ 2020-02-12 15:31 sqsq 阅读(186) 评论(0) 推荐(0) 编辑
摘要:顾名思义,像尺子一样取一段,尺取法通常是对数组保存一对下标,即所选取的区间的左右端点,然后根据实际情况不断地推进区间左右端点以得出答案。之所以需要掌握这个技巧,是因为尺取法比直接暴力枚举区间效率高很多,尤其是数据量大的时候,所以尺取法是一种高效的枚举区间的方法,一般用于求取有一定限制的区间个数或最短 阅读全文
posted @ 2020-02-11 23:55 sqsq 阅读(346) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示