Codeforces 818G - Four Melodies 费用流 and DP( Codeforces 813D two melodies)

该博客探讨了如何使用最大费用最大流的方法解决Codeforces上的818G - Four Melodies问题,同时涉及813D - Two Melodies的相似策略。文章介绍了寻找四个满足特定条件的子序列的解题思路,虽然在图的压缩部分存在一些疑问,但提供的代码已经能够正确解决问题。
摘要由CSDN通过智能技术生成

题意:找四个子序列满足相邻元素 要么相差1要么模7相等

解:

1、最大费用最大流;

(压缩图的地方目前还有些困惑)但是代码是对的

#include<bits/stdc++.h>
#define en '\n'
#define ll long long
using namespace std;
const int N=3010,M=2*(4*N+(N*(N-1))/2);
const int inf=0x3f3f3f3f;
int ver[M],edge[M],cost[M],Next[M],head[M];
int d[N<<1],incf[N<<1],pre[N<<1],v[N<<1];
int n,k,tot,s,t,maxflow,ans;
void add(int x,int y,int z,int c){
    ver[++tot]=y,edge[tot]=z,cost[tot]=c;
    Next[tot]=head[x],head[x]=tot;
    ver[++tot]=x,edge[tot]=0,cost[tot]=-c;
    Next[tot]=head[y],head[y]=tot;
}
queue<int>q;
#define mem(a,b) memset(a,b,sizeof(a))
inline bool spfa(){
    while(!q.empty())q.pop();
    for(int i=1;i<=2*n+20;i++)d[i]=0xcfcfcfcf,v[i]=0;
    q.push(s);d[s]=0;v[s]=1;
    incf[s]=1<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值