POJ 2531

简介: 初学dfs参考别人代码,如有雷同,见怪不怪。#include using namespace std; int aa[25][25]; int maxa=0; int step[25]={0},n; void dfs(int a,int b) { int t=b; step...
初学dfs参考别人代码,如有雷同,见怪不怪。

#include<iostream> using namespace std; int aa[25][25]; int maxa=0; int step[25]={0},n; void dfs(int a,int b) { int t=b; step[a]=1; for(int i=0;i<n;i++) { if(step[i]==0) t+=aa[a][i]; else t-=aa[a][i]; } if(maxa<t) maxa=t; for(int j=a+1;j<n;j++) { dfs(j,t); step[j]=0;//因为一底层的循环从头看开始所以要清0 } } int main() { cin>>n; for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>aa[i][j]; dfs(0,0); cout<<maxa<<endl; return 0; }

 

相关文章
|
7月前
Hopscotch(POJ-3050)
Hopscotch(POJ-3050)
|
算法框架/工具
POJ 2262 Goldbach's Conjecture
POJ 2262 Goldbach's Conjecture
143 0
POJ 1936 All in All
POJ 1936 All in All
80 0
POJ 1012 Joseph
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53862   Accepted: 20551 Description The Joseph's problem is notoriously known.
845 0
|
测试技术
poj-1218 THE DRUNK JAILER 喝醉的狱卒
自己去看看原题; 题目大意: 就是一个狱卒喝醉了,他第一趟吧所有的监狱都带开,第二趟把能把二整除的监狱关闭,第三趟操作能把三整除的监狱; 求最后能逃跑的罪犯数 输入第一个数是代表 测试数据组数 每个数据代表狱卒来回的次数 当作开关问题即可 #include using names...
1015 0
POJ-1003-hangover
Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length.
769 0
POJ 2487 Stamps
Description Background Everybody hates Raymond. He’s the largest stamp collector on planet earth and because of that he always makes fun of all the others at the stamp collector parties.
1069 0
|
机器学习/深度学习