最大团模板

用于求最大团的点数
只要在mp中赋值好n个点对其他所有的点的关系即可


#include<bits/stdc++.h> using namespace std; #define N 60 int n; int mp[N][N]; int ans; int alt[N][N]; int Max[N]; bool dfs(int cur,int tot)//cur是s1集合的个数 { if(0==cur) { if(tot>ans) { ans=tot;return true; } return false; } for(int i=0;i<cur;i++) { if( tot+cur-i<=ans )return false; int u=alt[tot][i]; if( Max[u]+tot<=ans )return false; int next=0; for(int j=i+1;j<cur;j++) if(mp[u][ alt[tot][j] ])alt[tot+1][next++]=alt[tot][j]; if(dfs(next,tot+1)) return 1; } return 0; } int maxclique(void) { ans=0; memset(Max,0,sizeof(Max)); for(int i=n-1;i>=0;i--) { int cur=0; for(int j=i+1;j<n;j++)if(mp[i][j])alt[1][cur++]=j;//1为s1集合 dfs(cur,1); Max[i]=ans; } return ans; } int main() { while(scanf("%d",&n),n) { for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d",&mp[i][j]); printf("%d\n",maxclique()); } return 0; }

 

转载于:https://www.cnblogs.com/bxd123/p/10387683.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用函数模板求最大值的方法是定义一个函数模板,该函数模板可以接受任意数量、任意类型的参数,并返回这些参数中的最大值。 以下是一个求最大值的函数模板的示例代码: ```cpp template<typename T> T maxele(T a) { return a; } template<typename T, typename... Args> T maxele(T a, Args... arg) { return max(a, maxele(arg...)); } ``` 在这个示例代码中,`maxele`函数模板有两个重载版本。第一个版本接受一个参数,直接返回该参数。第二个版本接受一个或多个参数,并使用递归调用来比较参数的大小,最终返回最大值。 你可以根据需要调用这个函数模板来求任意数量、任意类型的参数的最大值。例如,你可以使用整型或双精度类型的数组来调用这个函数模板,如下所示: ```cpp int intArray[] = {1, 2, 3, 4, 5}; double doubleArray[] = {1.1, 2.2, 3.3, 4.4, 5.5}; int maxInt = maxele(intArray<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [C++可变参模板使用(实现求最大值)、tuple实现、type_traits的使用、去除const模板的使用、initializer_list...](https://blog.csdn.net/w_weixiaotao/article/details/108519383)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [c++知识点---函数模板实现求数组的最大值](https://blog.csdn.net/tobe_numberone/article/details/78149922)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值