
acwing题解
acwing题解
_zpf
这个作者很懒,什么都没留下…
展开
-
判断负环例题
acwing 904虫洞#include<bits/stdc++.h>using namespace std;#define N 510#define M 6010int ne[M],to[M],h[N],w[M];int m,n,t,cnt;int rem[N];//the number of the point passed byvoid add( int a,int b,int c){ w[cnt]=c;to[cnt]=b;ne[cnt]=h[a];h[a]=cnt原创 2021-07-17 22:35:56 · 168 阅读 · 0 评论 -
区间のdp
区间dp首先从小到大枚举区间长度l。然后枚举区间的起始点i。然后枚举区间的分割点d。acwing 282 石子合并/《算法竞赛进阶指南》#include<bits/stdc++.h>using namespace std;#define N 310int n;int a[N];int dp[N][N];//两个维度分别是首尾指针int pre[N];int main(){ cin>>n; for( int i=1;i<=n;i++){原创 2021-07-11 22:58:53 · 98 阅读 · 0 评论 -
最小生成树
acwing 1140《信息学奥赛一本通》最短网络#include<bits/stdc++.h>using namespace std;#define N 110typedef long long ll;ll a[N][N];ll dist[N];bool vis[N];int n;ll prim(){ int start=1; ll res=0; dist[1]=0; vis[1]=1; //要先将一号节点加入集合 for( i原创 2021-07-11 14:10:57 · 106 阅读 · 0 评论 -
单源最短路的综合应用
acwing 1135/《信息学奥赛一本通》新年好#include<bits/stdc++.h>using namespace std;#define N 50010#define M 200100int n,m;int qq[10];int w[M],to[M],ne[M],h[N];int cnt;void add( int a,int b,int c){ w[cnt]=c;to[cnt]=b;ne[cnt]=h[a];h[a]=cnt++;}int dis[1原创 2021-07-10 19:30:04 · 110 阅读 · 0 评论 -
图论问题总结
算法的选择spfa算法,平均时间复杂度是O(m),最坏时间复杂度是O(mn),使用的时候要注意。朴素迪杰斯特拉算法时间复杂度是O(nn)堆优化的迪杰斯特拉算法时间复杂度是O(nlogm)三种算法使用时注意选择。图的建立建图时注意数据范围,如果时双向边注意开两倍空间n比较小时使用邻接矩阵,n比较打时使用邻接表存储...原创 2021-07-09 22:09:49 · 205 阅读 · 0 评论 -
单源最短路问题。
acwing 1129 热浪#include<bits/stdc++.h>using namespace std;#define N 2510#define M 16300int w[M],to[M],ne[M],h[N];int cnt;int dist[N],vis[N];int n,m,be,en;queue<int>q;void add( int a,int b,int c){ w[cnt]=c;to[cnt]=b;ne[cnt]=h[a];h[a原创 2021-07-08 20:36:35 · 136 阅读 · 0 评论 -
动态规划汇总
最长子序列问题:是一种序列dp,相邻的两个数之间有关系背包问题是一种组合dp:不考虑相邻两个数之间的关系,考虑数之间的组合关系原创 2021-07-07 19:40:31 · 70 阅读 · 0 评论 -
背包经典问题
acwing423采药#include<iostream>#include<stack>#include<string.h>#include<algorithm>#include<sstream>using namespace std;int w[1010];int cost[1010];int dp[1010][1010];int main(){ int t; int m; for( int i=1;i<=n;i原创 2021-07-07 16:25:58 · 112 阅读 · 0 评论 -
上升子序列模型。
acwing1017/《信息奥赛一本通》#include<bits/stdc++.h>using namespace std;int a[1010];int dp[1010];int main(){ int t; cin>>t; while(t--){ int n; cin>>n; for( int i=1;i<=n;i++){ scanf("%d",&a[i]); } int ans=0; memset(dp原创 2021-07-05 20:45:37 · 83 阅读 · 0 评论 -
树状のdp
树的最长路径//树型dp求解带权树的最大直径//先将树挂起来,易知,树的直径一定产生于某个节点的两个向下最长边#include<bits/stdc++.h>using namespace std;#define N 100100#define M 200100 int h[N],to[M],ne[M],w[M];//其中 M长度的数组模拟一个结构体链式前向星,ne存储下一个节点的位置 //to存储这条边连接的点int cnt=0;void add( int a,int b,原创 2021-07-05 16:18:38 · 176 阅读 · 0 评论 -
状态压缩dp
acwing 1064. 小国王/《信息学奥赛一本通》, SGU223, SCOI2005//1.枚举本行的放置方法//2.与上一行的放置方法进行计算,如果可行,就在dp数组中加入//需要记忆上一行的放置方法并且和放置的个数一一对应 #include<bits/stdc++.h>using namespace std;#define N 12int n,k;const int M=(1<<N); long long dp[N][N*N][M];//含义是第n行 k个原创 2021-07-04 15:23:20 · 173 阅读 · 0 评论 -
acwing状态机模型
AcWing 1049. 大盗阿福#include<iostream>#include<algorithm>#include<string.h>using namespace std;int a[100100];int dp[100100][2];int main(){ int t; int n; cin>>t; while(t--){ memset(dp,0,sizeof(dp)); cin>>n; for(原创 2021-07-03 19:47:49 · 131 阅读 · 0 评论