找到 34423 篇文章 关于编程

用 C++ 计算 mXn 矩阵左上角到右下角的所有可能路径

Ayush Gupta
更新于 2020年2月10日 12:08:04

180 次浏览

在本教程中,我们将讨论一个程序,用于查找从 mXn 矩阵的左上角到右下角的所有可能路径的数量。为此,我们将提供一个 mXn 矩阵。我们的任务是找到给定矩阵的左上角到右下角的所有可能路径。示例#include using namespace std; //返回可能路径的数量 int count_paths(int m, int n){    if (m == 1 || n == 1)       return 1;    return count_paths(m - 1, n) + count_paths(m, n - 1); } int main(){    cout

用 C++ 计算两个顶点之间所有可能的路径

Ayush Gupta
更新于 2020年2月10日 12:06:13

315 次浏览

在本教程中,我们将讨论一个程序,用于查找两个顶点之间路径的数量。为此,我们将提供一个有向图。我们的任务是找到两个给定顶点之间所有可能的路径数量。示例#include using namespace std; //构造一个有向图类 Graph{    int V;    list *adj;    void countPathsUtil(int, int, bool [], int &);    public:       //构造函数       Graph(int V);       void addEdge(int u, int v);       int countPaths(int s, int d); }; Graph::Graph(int V){    this->V = V;    adj ... 阅读更多

用 C++ 计算满足给定条件的所有可能的 N 位数字

Ayush Gupta
更新于 2020年2月10日 12:02:03

120 次浏览

在本教程中,我们将讨论一个程序,用于查找满足给定条件的所有可能的 N 位数字的数量。为此,我们将提供一个整数。我们的任务是检查哪个 N 位数满足Number + Reverse(Number) = 10N -1示例#include using namespace std; //返回数字的个数 string count_num(int N){    if (N % 2 == 1)       return 0;    string result = "9";    for (int i = 1; i

用 C++ 计算所有大小为 2 或 3 且和为 3 的倍数的组

Ayush Gupta
更新于 2020年2月10日 11:59:37

203 次浏览

在本教程中,我们将讨论一个程序,用于查找所有大小为 2 或 3 且和为 3 的倍数的组的数量。在本教程中,我们将讨论一个程序,用于查找所有大小为 2 或 3 且和为 3 的倍数的组的数量。示例#include using namespace std; //返回 2 或 3 个对的数量 int count_groups(int arr[], int n){    int c[3] = {0}, i;    int res = 0;    for (i=0; i>1);    res += c[1] * c[2];    res += (c[0] * (c[0]-1) * (c[0]-2))/6; ... 阅读更多

用 C++ 计算一个数的所有完全除数

Ayush Gupta
更新于 2020年2月10日 11:44:32

222 次浏览

在本教程中,我们将讨论一个程序,用于查找一个数的所有完全除数的数量。为此,我们将提供一个数。我们的任务是计算给定数的所有完全除数。示例#include using namespace std; //检查完全平方数 bool if_psquare(int n){    int sq = (int) sqrt(n);    return (n == sq * sq); } //返回完全除数的数量 int count_pdivisors(int n){    int count = 0;    for (int i=1; i*i

用 C++ 计算给定字符串中的所有回文子序列

Ayush Gupta
更新于 2020年2月10日 11:24:43

168 次浏览

在本教程中,我们将讨论一个程序,用于查找给定字符串中所有回文子序列的数量。为此,我们将提供一个字符串。我们的任务是找到给定字符串中可以生成的回文子序列的数量。示例#include #include using namespace std; //返回回文序列总数 int count_palin(string str){    int N = str.length();    //创建一个二维数组    int cps[N+1][N+1];    memset(cps, 0 ,sizeof(cps));    for (int i=0; i

用 C++ 计算所有是回文数的平方数

Ayush Gupta
更新于 2020年2月10日 11:20:53

140 次浏览

在本教程中,我们将讨论一个程序,用于查找是回文数平方的回文数的数量。为此,我们将提供两个值 L 和 R。我们的任务是在给定范围内找到超级回文数的数量。超级回文数是指数字及其平方都是回文数的数字。示例#include using namespace std; //检查数字是否为回文数 bool if_palin(int x){    int ans = 0;    int temp = x;    while (temp > 0){       ans = 10 * ans + ... 阅读更多

用 C++ 计算字符串中的所有回文子字符串

Ayush Gupta
更新于 2020年2月10日 11:13:53

170 次浏览

在本教程中,我们将讨论一个程序,用于查找字符串中回文子字符串的数量。为此,我们将给出一个字符串。我们的任务是计算给定字符串中长度大于 3 的回文子字符串的数量。示例#include using namespace std; //计算回文字符串 int count_pstr(char str[], int n){    int dp[n][n];    memset(dp, 0, sizeof(dp));    bool P[n][n];    memset(P, false , sizeof(P));    for (int i= 0; i< n; i++)       P[i][i] = true;    for (int i=0; i

用 C++ 计算所有具有给定 XOR 的对

Ayush Gupta
更新于 2020年2月10日 11:07:13

199 次浏览

在本教程中,我们将讨论一个程序,用于查找具有给定 XOR 的对的数量。为此,我们将提供一个数组和一个值。我们的任务是找到 XOR 等于给定值的对的数量。示例#include using namespace std; //返回具有 XOR 等于给定值的对的数量 int count_pair(int arr[], int n, int x){    int result = 0;    //处理重复值    unordered_map m;    for (int i=0; i

用 C++ 计算数组中所有在 K 位上不同的对

Ayush Gupta
更新于 2020年2月10日 10:55:19

125 次浏览

在本教程中,我们将讨论一个程序,用于查找数组中在 K 位上不同的对的数量。为此,我们将提供一个数组和一个整数 K。我们的任务是找到其二进制表示中相差 K 位的对的数量。示例#include using namespace std; //计算二进制表示中的位数 int count_bit(int n){    int count = 0;    while (n) {       if (n & 1)          ++count;       n >>= 1;    }    return count; } ... 阅读更多

广告

© . All rights reserved.