自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(25)
  • 收藏
  • 关注

原创 输入n打印菱形

int main()int n;cin >> n;i<n;i++){j < n;j ++ ){cout<<"*";return 0;

2023-07-11 23:52:32 130

原创 0-1背包问题

#include<iostream>using namespace std;#define NUM 50//物品数量上限#define CAP 1500//背包容量上限int w[NUM];//物品的重量int v[NUM];//物品的价值int x[NUM];//记录哪个物品被选择int p[NUM][CAP];//用于递归的数组 p[i][j]的意思是,当背包容量暂时限定为j时,物品从n,n-1....i挑选。void knapsack(int n,int c)//n是物品.

2022-05-03 20:57:22 192

原创 最大子段和

#include<iostream>using namespace std;#define NUM 1001int a[NUM];int b[NUM];//b[i]是以a[i]为结尾时对应的的最大子段和。MAX=max(b[i])。返回b的最大值。int Maxsum(int n){ int sum = 0; int left=0, right=0;//left表示起点,right表示终点。 for (int i = 1; i <= n; i++)...

2022-05-03 20:23:06 232

原创 最长公共子序列

#include<iostream>using namespace std;#define NUM 100int c[NUM][NUM];//c[i][j]用来记录序列Xi和Yj最长公共子序列的长度。其中Xi和Yj的下标都是从1开始。int b[NUM][NUM];//辅助数组,b[i][j]记录c[i][j]的值是由哪个子问题的解得到的。void LCSLength(char x[], int m, char y[], int n){ //当i=0||j=0 最长公共子序列...

2022-05-03 20:17:08 116

原创 矩阵连乘积问题

#include<iostream>using namespace std;#define NUM 51int p[NUM];//用来记录矩阵的维数int m[NUM][NUM];//m[i][j]表示计算从Ai到Aj这些矩阵相乘所需要的最小次数。所以本题的答案是m[1][n]的值。int s[NUM][NUM];//数组s用来表示最优断开位置。int MatriChain(int n)//本题需要填m矩阵的右上方的元素值。{ for (int i = 1; i <=...

2022-05-03 20:10:40 69

原创 半数集问题

#include<iostream>using namespace std;int a[1001];int comp(int n){ int ans = 1;//该数本身也属于半数集,故初始个数为1 if (a[n] > 0)//递归返回到这一步,如果a[n],不等于0,说明子问题已得到解决,不需要递归到底,避免了重复。 { return a[n]; } for (int i = 1; i <= n / 2; i++)/...

2022-05-03 19:58:54 190

原创 输油管问题

#include<iostream>#include<cmath>using namespace std;#define NUM 1001int a[NUM];int select(int left, int right, int k)//采用分治算法计算中位数。{ int i = left; int j = right; int pivot = a[left]; while (true) { while (a[i]...

2022-05-03 19:51:51 320

原创 选择问题001

#include<iostream>#include<cmath>using namespace std;#define NUM 1001int a[NUM];int select(int left, int right, int k)//left:数组起始下标(本题从0开始);right:终点下标;k:数组中第k小的数。{ int i = left;//i相当于指针(从左向右) int j = right;//j相当于指针(从右向左) int p...

2022-05-03 19:49:49 189

原创 循环赛日程表

#include<iostream>using namespace std;#define max 100int a[max][max];//输出的数组void table(int k)//k,表示参赛选手的数量{ int d = 1;//边长 A B a[1][1] = 1;//初始化 C D while (...

2022-05-03 19:41:04 193

原创 整数划分问题

#include<iostream>using namespace std;int split(int n, int m)//n 需要求得数。m:对n划分最大值不超过m{ if (n == 1 || m == 1)//只有一种划分,划分成1. { return 1; } else if (n < m)//如果m>n,其实没必要。比如对3划分最大值不超过7,和对3划分最大值不超过3一样。 { ...

2022-05-03 19:35:44 59

原创 集合的全排列问题

#include<iostream>using namespace std;void Perm(int list[], int start, int end)//start:起始下标;end:结束下标。{ if (start == end)//递归到底层 { for (int i = 0; i <= end; i++) { cout << list[i] << " "; }...

2022-05-03 19:32:48 58

原创 选择问题 输出第K小的数

#include<iostream>using namespace std;int select(int left, int right, int k,int a[],int n){ //if (left >= right)return a[left]; int i = left; int j = right; int pivot = a[left]; while (true) { while (a[i] < pi...

2022-03-10 21:16:16 83

原创 邻接表的实现

#include <iostream>using namespace std;struct EdgeNode{ int adjvex; EdgeNode* next;};struct VertexNode{ char vertex; EdgeNode* FirstEdge;};const int MaxSize = 10;int visited[MaxSize] ;class ALGraph{public: ALGraph(ch...

2021-12-24 22:33:20 696

原创 顺序查找和二分查找

#include<iostream>using namespace std;const int MaxSize = 100;class LineSearch{public: LineSearch(int a[], int n); int SeqSearch(int k); int BinSearch(int k);private: int data[MaxSize]; int length;};LineSearch::LineSearch(...

2021-12-21 21:27:11 57

原创 二叉链表的实现

#include<iostream>using namespace std;struct BiNode{ char data; BiNode* lchile, * rchile;};class BiTree{public: BiTree() { root = Creat(); } void PreOrder() { PreOrder(root); } void InOrder() { InOrder(root); } void Las...

2021-12-20 18:18:37 508

原创 随机生成7个1-30之间的整数,要求每次生成的随机数不允许有重复数据

package 期末复习练习;public class Sjs { public static void main(String[] args) { int p=0; int a[]=new int[7]; while(p<7) { int t=0; int x=(int)(Math.random()*30+1); for(int i=0;i<a.length;i++)...

2021-12-20 11:55:41 567

原创 输入一串字符统计字母出现的次数,不区分大小写

package 期末复习练习;import java.util.Scanner;public class Strin { public static void main(String[] args) { String s; System.out.println("请输入一串字符"); Scanner cin=new Scanner(System.in); s=cin.nextLine(); int a[]=ne...

2021-12-20 11:35:47 1877

原创 交换数组中元素的值(第一位与最后一位交换)

package 期末复习练习;public class Exchange { public static int []exchange(int a[]) { for(int i=0,j=a.length-1;i<=j;i++,j--) { int temp=a[i]; a[i]=a[j]; a[j]=temp; }return a; } ...

2021-12-19 22:23:25 1020

原创 Π/4=1-1/3+1/5-1/7+.......

利用给定公式求Π

2021-12-19 21:39:02 343

原创 链队列的使用

#include<iostream>using namespace std;struct Node{ int data; Node* next;};class LinkQueue{public: LinkQueue(); void EnQueue(int x); int DeQueue(); int GetHead();private: Node* front, * rear;};LinkQueue::LinkQueue...

2021-12-19 21:12:36 57

原创 循环队列的实现

#include<iostream>using namespace std;const int QueueSize = 100;class CirQueue{public: CirQueue(); void EnQueue(int x); int DeQueue(); int GetHead();private: int data[QueueSize]; int front, rear;};CirQueue::CirQueue()...

2021-12-19 20:52:26 125

原创 链栈的实现操作

#include<iostream>using namespace std;struct Node{ int data; Node* next;};class LinkStack{public: LinkStack(); void Push(int x); int Pop(); int GetTop();private: Node* top;};LinkStack::LinkStack(){ top = NUL...

2021-12-19 20:09:43 55

原创 顺序栈的实现

#include<iostream>using namespace std;const int MaxSize = 10;class Stack{public: Stack(); void Push(int x); int Pop(); int GetTop();private: int data[MaxSize]; int top;};Stack::Stack(){ top = -1;}void Stack::Pus...

2021-12-19 19:52:39 44

原创 单链表的实现

#include<iostream>using namespace std;struct Node{ int data; Node* next;};class LinkList{public: LinkList(int a[], int n); int Get1(int i); int Get2(int x); void Insert(int i, int x); int Delete(int i); void Pri...

2021-12-19 19:41:00 273

原创 顺序表的实现

#include<iostream>using namespace std;const int MaxSize = 100;class SeqList{public : SeqList(int a[], int n); int Get1(int i); int Get2(int x); void Insert(int i, int x); int Delete(int i); void PrintList();private: ...

2021-12-19 19:01:02 159

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除