- 博客(16)
- 收藏
- 关注
原创 放苹果
放苹果题目把 M 个同样的苹果放在 N 个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?注意:5、1、1 和 1、5、1 是同一种分法,即顺序无关。代码思路#include <iostream>using namespace std;int f(int m, int n){ if (n == 1||m == 0)//假如盘子为一个或者苹果为0;则return 1; { return 1; } if (m < n)
2021-05-13 16:18:54
90
原创 数组的子集c++
数组的子集输入一个数组,求这串数字的子集#include <iostream>#include <bits/stdc++.h>using namespace std;int sr[100];//定义一个数组bool se[100];//定义一个bool数组来判断是否将父节点输出 int n;//数组长度void str(int i){ if (i >= n) { int flag=0;//定义flag用来输出空集
2021-05-12 16:46:21
432
原创 最少支付问题c++
最少支付问题问题描述已知某货币体系为(c0, c1, c2, …, c7),c>1,要支付指定的金额 N,最少需要多少个货币,请写出求解算法代码,并证明算法的正确性。代码#include <iostream>using namespace std;int s[] = {100, 50, 20, 10, 5, 2, 1};int q[100];int main(){ int n; //循环次数 int m; //你将要计算的金额
2021-05-12 10:47:09
423
原创 bool函数
bool函数bool 的返回值有true和false,true默认为1,false默认为0#include<iostream>using namespace std;int main(){ bool a; cout<<a; cout<<endl; bool b=2; cout<<b;}结果
2021-05-11 15:50:18
4273
原创 0-1背包问题 c++
0-1背包问题#include<iostream>#include<bits\stdc++.h>using namespace std;int f[5][9]={0};//定义一个二维数组,用来比较int w[5]={0,2,3,4,5};//物品的重量int v[5]={0,3,4,5,8};//物品的价值int main(){ memset(f,0,sizeof(f));//将二维数组元素置0 for(int i=1;i<5;i++)
2021-05-11 15:26:02
96
原创 sort函数
sort函数头文件#include<algorithm>代码#include<iostream>#include<algorithm>using namespace std;int main(){ int a[]={123,32,3,4554,5};//定义一个数组 sort(a,a+5);//对数组进行排序,默认从小到大 for(int i=0;i<5;i++) { cout <<a[i
2021-05-11 15:07:05
77
原创 set的用法
C++中Set的用法set的基本用法multiset的基本用法#include<iostream>#include<set>using namespace std;int main(){ int b[]={12,34,54,6,6,76,8};//定义一个数组,并输入 set<int>a(b,b+7);//使用set进行排序,相同元素只保留一个 for(set<int>::iterator i=a.begin();i!=a
2021-05-11 11:36:15
228
原创 二分搜索
二分搜索二分搜索解决思路代码二分搜索二分搜索是典型的分治策略,对于一个已经排好顺序的数组a[n],在其中寻找一个特定的元素x。解决思路1.传统思路:采用顺序搜索法,但是时间复杂度较大2.二分搜索:对于已经排好顺序的数组,我们找到其中间元素a[n/2]与我们需要寻找特定元素x比对,如果x>a[n/2],则在数组a[m]的右半部分重复操作,如果x<a[m],则在左半部分重复操作,如果x=a[n/2],则结束。代码#include<iostream>using namesp
2021-05-11 10:11:05
134
空空如也
需要自然语言处理方面的帮助
2023-05-03
TA创建的收藏夹 TA关注的收藏夹
TA关注的人