摘要: 点击查看代码 /* 第1行给出物品数量n和背包容量V,第2行给出每件物品的重量为w[i],第3行给出每件物品的价值为c[i]。现在需要选出若干件物品放入一个容量为V的背包中, 使得在选入背包的物品重量和不超过V的前提下,让背包中物品的价值之和最大,输出最大价值(1<=n<=20) 这个问题属于常见的 阅读全文
posted @ 2022-09-29 21:22 zhaoo_o 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<cstdio> #pragma warning(disable:4996) //并查集的基本操作 const int maxn = 1001; //最多1000个元素 int n; //并查集元素个数 int father[maxn]; //存储并查集元素 //查找元 阅读全文
posted @ 2022-09-29 21:21 zhaoo_o 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<cstdio> #include<stdlib.h> //malloc() //链表结点定义 struct Node { int data; //数据域 int next; //指针域 }node[10000]; //node是静态链表,大小为10000 int ma 阅读全文
posted @ 2022-09-29 21:20 zhaoo_o 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<cstdio> #include<stdlib.h> //malloc() //链表结点定义 struct node { int data; //数据域 node* next; //指针域 }; //创建链表,将Array[]每个元素存入链表的每个结点内 node* 阅读全文
posted @ 2022-09-29 21:20 zhaoo_o 阅读(30) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 /* 给出一个只包含+,-,x,/的非负整数计算表达式,计算该表达式的值,结果保留2位小数点 表达式不超过200个字符,整数和运算符之间用一个空格分隔,没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出 输入样例1: 30 / 90 - 26 + 97 - 5 - 6 - 1 阅读全文
posted @ 2022-09-29 21:17 zhaoo_o 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<cstdio> #pragma warning(disable:4996) //组合数C(n,m)的计算 //方法1:通过定义式计算,因为涉及阶乘结果大,long long型只能接收n<=20的数据范围 long long C(long long n, long lo 阅读全文
posted @ 2022-09-29 21:09 zhaoo_o 阅读(241) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<cstdio> #pragma warning(disable:4996) //非递归计算n!中含有多少个质因子p int cal(int n, int p) { int ans = 0; //记录p的总个数 //当n为0时结束 while (n) { ans += 阅读全文
posted @ 2022-09-29 21:07 zhaoo_o 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<cstdio> #pragma warning(disable:4996) //给定a、b,通过欧几里得算法求解a和b的最大公约数gcd(a,b) int gcd(int a, int b) { if (b == 0) return a; else return gc 阅读全文
posted @ 2022-09-29 21:06 zhaoo_o 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 //大整数存储 #include<cstdio> #include<cstring> //使用strlen()和memset() #pragma warning(disable:4996) //bign结构体存储大整数的值和它的位数 struct bign { int d[1000]; 阅读全文
posted @ 2022-09-29 21:04 zhaoo_o 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<cstdio> #include<cmath> //使用sqrt() #pragma warning(disable:4996) //对正整数n进行质因子分解 const int factor_maxnum = 10; //对于int型范围的数,它的质因子种类不超过1 阅读全文
posted @ 2022-09-28 23:08 zhaoo_o 阅读(12) 评论(0) 推荐(0) 编辑