![](https://img-blog.csdnimg.cn/20190927151101105.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
蓝桥杯C/C++编程竞赛
分享个人写过的一些题型
大梁啊
长风破浪会有时
展开
-
求最大公约数、最小公倍数
最大公约数:辗转相除法int func(int a, int b){ if(a==0) { return 0; } return func(b,a%b);}最小公倍数:两个数的乘积 是 最小公倍数和最大公约数的乘积...原创 2019-04-01 18:09:48 · 86 阅读 · 0 评论 -
DFS最长公共子序列
//最长公共子序列//a123b4c//1234abc#include <iostream>#include <string>using namespace std;string dfs(string str1,string str2){ int len1=str1.length(); int len2=str2.length(); stri...原创 2019-05-21 11:49:46 · 294 阅读 · 0 评论 -
//在数字等边三角形中寻找一条从顶部到底边的路径,使得路径上所经过的数字之和最大,路径上的每一步都只能往右下或左下走,只需求出最大和即可,不必给出具体路径
// 7// 3 8// 8 1 0// 2 7 4 4//4 5 2 6 5 #include <iostream>using namespace std;int max(int a,int b){ if(a>b) { return a; } return b;}int dp(int **arr,int n){ if(!(n...原创 2019-05-20 17:15:49 · 2247 阅读 · 0 评论 -
DP钢条切割问题:将长为n的钢条,切割成m段,不同长度的钢条市场价格不同,切割本身没有成本,求最大价值的切割方案
//长度1,2,3,4,5,6,7,8,9,10//价格1,5,8,16,10,17,17,20,24,30 //n为钢条长度,m为可切割的数据组数 //输入示例:10 10 1 5 8 16 10 17 17 20 24 30 //结果:37#include <iostream>#include <vector>using namespace std;i...原创 2019-05-20 11:12:55 · 1147 阅读 · 0 评论 -
水洼问题:一个水坑附近如果存在另一个水坑则视为连接在一起,视做一个水洼,附近指的是八连通,给定一个地图,问有多少个水洼及水洼的大小
#include <iostream>#include <string>#include <queue>using namespace std;//水洼问题,八连通的积水被认为是连在一起的,构成一个水洼,问有多少个水洼struct point{ int x; int y; int counts;};queue<point> s...原创 2019-05-14 20:09:49 · 936 阅读 · 0 评论 -
括号组合问题:有n个括号,请问有多少种合理的组合方式?
#include <set>#include <iostream>#include <string>using namespace std; set<string> func(int n) { set<string> s_n; if(n==1) { s_n.insert("()"); retu...原创 2019-05-14 17:56:04 · 1861 阅读 · 0 评论 -
上台阶问题:一个人上台阶,一次可以走1、2、3步,问n个台阶有多少种走法?
#include <iostream>using namespace std;int func(int a){ if (a==1 || a==0) { return 1; } if (a<1) { return 0; } if (a==2) { return 2; } return func(a - 1) + func(a - 2) + f...原创 2019-05-14 17:52:46 · 5503 阅读 · 1 评论 -
非数值型集合的任意子集
#include <iostream>#include <set>#include <string>using namespace std;set<string> func(string arr[],int n){ set<string> s; s.insert(""); for(int i=0;i<n;i++)...原创 2019-05-14 17:48:53 · 138 阅读 · 0 评论 -
非数值型集合的全排列个数
#include <iostream>#include <string>#include <set>using namespace std;set<string> func(int n, string str){ set<string> s; string temp,temp2; if (n == 0) { tem...原创 2019-05-14 17:47:52 · 128 阅读 · 0 评论 -
给定若干个数字,每个数字至多使用一次,能否凑出某个数
#include <iostream>#include <set>using namespace std;//1,2,4,7能否凑13void func(int num,int arr[4],int i,set<int> noumber){ if (num==13) { for (set<int>::iterator it=noum...原创 2019-05-14 17:45:09 · 1076 阅读 · 0 评论 -
dp背包问题:将n个物品放进背包里,背包容量为m,物品具有重量和价值两个属性,要求背包所放物品的价值最大,物品不可被切割
//将n个物品放进背包里,背包容量为m,物品具有重量和价值两个属性,要求背包所放物品的价值最大,物品不可被切割//举例:4个物品,背包容量为5,每个物品属性(2,3) (1,2)(3,4)(2,2)//输入示例:4 5 2 3 1 2 3 4 2 2//输出结果为7 #include <iostream>#include <vector>using names...原创 2019-05-19 16:00:26 · 4157 阅读 · 0 评论 -
C++,DFS深度优先,数独游戏
#include <iostream>using namespace std;bool res(int arr[][9], int x, int y, int n){ //行列有无重复 for (int i = 0; i < 9; i++) { if (arr[x][i]==n) { return false; } if (arr[i][y] ...原创 2019-05-13 22:30:56 · 487 阅读 · 0 评论 -
bfs广度优先迷宫,最短路径
//只能判断能不能走通,不能得到路径#include #include using namespace std;struct point{int x, y, dis;};int fx[4] = { 1,-1,0,0 },fy[4] = { 0,0,1,-1 };int bfs(int x, int y, int a, int b, int maze[][9]){queue m...原创 2019-04-15 15:52:21 · 329 阅读 · 0 评论 -
DP最长公共子序列
//最长公共子序列//ab34c//a1bc2#include <iostream>#include <string>using namespace std;int max(int a, int b){ if (a > b) { return a; } return b;}string dp(string str1, string ...原创 2019-05-21 21:58:50 · 138 阅读 · 0 评论