hdu 5772 String Problem

本文深入探讨了网络流算法中的最大权闭合子图问题,通过具体题目解析,介绍了如何使用最小割方法解决涉及物品选择和组合价值的问题。特别讨论了物品分类的额外代价处理技巧,提供了详细的代码实现。

题目

给你一个包含0-9的序列,如果你选择了这个序列的第i位和第j为,那么你能得到w[i][j]+w[j][i]的收益,然后对于你选择的那些数字是有一定的花费的,花费为a[i]*(k-1)+b[i],a[i]和b[i]是数字i的两个参数,k代表数字i选了多少次。

题解

其实就是最大权闭合子图的变式。
顺便回顾了最大权闭合子图的写法。下面会用(u,v,上限)这种形式表示建边。
一般是用于,需要付出代价选每个物品,某些物品凑一起组合可以产生一定价值。
方法是最小割。先假设拿到所有的价值,不付出代价,建立类似二分图,左边一排是物品,右边是组合,先(当前组合所需每个物品,组合,INF)然后(S,每个物品,物品代价) (每个组合,T,组合收益)
答案=所有价值-最小割
如果最小割中,某个物品与S的边被割了,说明选了这个物品,付出了代价,某个组合与T的边被割了,说明这个组合没有凑成,这个价值没有拿到。

然而在此题中有变式,物品被分为几类,第一次拿某类物品需要付出额外代价。也就是只要拿了这类物品就需要付出一个代价。可以给每类一个节点,(S,类节点,对应代价)(*),(类节点,所有该类物品,INF),可以发现,如果选了该类某个物品,那么( *)边必然会被割掉,因为不割会出现一条显然的增广路,并且也不会影响物品单独的代价。

代码

可能有同学看不懂我的语言。。我贴一下建边的代码,Dinic的板子就不帖了。
啊。。这个高亮有点亮

#define rep(i,x,y) for(int i=x;i<=y;++i)

		int n,ans=0;cin>>n;
		scanf("%s",s+1);
		rep(i,0,9) scanf("%d%d",a+i,b+i);
		rep(i,1,n) rep(j,1,n) {
			scanf("%d",w[i]+j);
			if(i!=j) ans+=w[i][j];
		}
		S=n*n+11,T=S+1;
		rep(i,1,n) add_edge(S,i,a[s[i]-'0'],0);

		int cur=n+1;
		rep(i,1,n) rep(j,1,n) if(i!=j){
			add_edge(i,cur,INF,0);
			add_edge(j,cur,INF,0);
			add_edge(cur,T,w[i][j],0);
			++cur;
		}
		rep(i,1,n) add_edge(n*n+s[i]-'0'+1,i,INF,0);
		rep(i,0,9) add_edge(S,n*n+i+1,b[i]-a[i],0);
		int mf=MF();
		printf("Case #%d: %d\n",++kase,ans-mf);

后记

啊啊啊啊网络流什么都不记得了真的是菜死我了。
另外也不是很明白网络流的复杂度,二分图,大概1w多个点,3w条边,20组居然能跑得这么快的吗,Dinic跑了31ms。。可能是我对他们复杂度有什么误解。

【激光质量检测】利用丝杆与步进电机的组合装置带动光源的移动,完成对光源使用切片法测量其光束质量的目的研究(Matlab代码实现)内容概要:本文研究了利用丝杆与步进电机的组合装置带动光源移动,结合切片法实现对激光光源光束质量的精确测量方法,并提供了基于Matlab的代码实现方案。该系统通过机械装置精确控制光源位置,采集不同截面的光强分布数据,进而分析光束的聚焦特性、发散角、光斑尺寸等关键质量参数,适用于高精度光学检测场景。研究重点在于硬件控制与图像处理算法的协同设计,实现了自动化、高重复性的光束质量评估流程。; 适合人群:具备一定光学基础知识和Matlab编程能力的科研人员或工程技术人员,尤其适合从事激光应用、光电检测、精密仪器开发等相关领域的研究生及研发工程师。; 使用场景及目标:①实现对连续或脉冲激光器输出光束的质量评估;②为激光加工、医疗激光、通信激光等应用场景提供可靠的光束分析手段;③通过Matlab仿真与实际控制对接,验证切片法测量方案的有效性与精度。; 阅读建议:建议读者结合机械控制原理与光学测量理论同步理解文档内容,重点关注步进电机控制逻辑与切片数据处理算法的衔接部分,实际应用时需校准装置并优化采样间距以提高测量精度。
### HDU 2894 Problem Solution The task involves creating the shortest possible string that retains all characters from two provided strings while maintaining their original sequence. This problem can be approached using dynamic programming (DP). The core idea is to find common subsequences between both strings efficiently. #### Dynamic Programming Approach To solve this issue effectively, one method employs DP tables where each entry `dp[i][j]` represents the minimum length needed when considering substrings up until positions i and j respectively within the first and second word[^3]. For instance: Given sample inputs like those described in the reference material[^2], an effective strategy would involve constructing a table iteratively based on whether matching letters exist at current indices across compared words. If they do match, no additional character needs adding; otherwise, take into account extending either substring by including its next unmatched letter. ```python def compute_shortest_name(fruit1, fruit2): m, n = len(fruit1), len(fruit2) # Initialize DP matrix with dimensions (m+1)x(n+1) dp = [[0] * (n + 1) for _ in range(m + 1)] # Fill base cases along edges representing empty prefixes/suffixes for i in range(1, m + 1): dp[i][0] = i for j in range(1, n + 1): dp[0][j] = j # Populate remaining cells according to recurrence relation for i in range(1, m + 1): for j in range(1, n + 1): if fruit1[i - 1] == fruit2[j - 1]: dp[i][j] = dp[i - 1][j - 1] + 1 else: dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1 result_length = dp[m][n] # Reconstruct resulting merged string backwards starting from bottom-right corner index_i, index_j = m, n output_string = [''] * result_length while index_i > 0 or index_j > 0: if index_i > 0 and index_j > 0 and fruit1[index_i - 1] == fruit2[index_j - 1]: output_string[result_length - 1] = fruit1[index_i - 1] index_i -= 1 index_j -= 1 elif index_i > 0 and (index_j == 0 or dp[index_i - 1][index_j] < dp[index_i][index_j - 1]): output_string[result_length - 1] = fruit1[index_i - 1] index_i -= 1 else: output_string[result_length - 1] = fruit2[index_j - 1] index_j -= 1 result_length -= 1 return ''.join(output_string) # Example usage demonstrating how function works with test data points as per specification. print(compute_shortest_name('abc', 'bcd')) # Expected Output: abcd ``` This code snippet demonstrates building upon previously computed values through iteration over pairs of indexes corresponding to respective lengths traversed so far inside source terms being concatenated together optimally without redundancy whenever feasible under constraints outlined earlier regarding valid transformations allowed during processing steps involved hereafter.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值