vb 导出整数 科学计数法

Problem statement:

问题陈述:

Given two positive integer n and m, find how many arrays of size n that can be formed such that:

给定两个正整数nm ,找出可以形成多少个大小为n的数组:

  1. Each element of the array is in the range [1, m]

    数组的每个元素都在[1,m]范围内

  2. Any adjacent element pair is divisible, i.e., that one of them divides another. Either element A[i] divides A[i + 1] or A[i + 1] divides A[i].

    任何相邻的元素对都是可分割的 ,即,其中一个元素对另一个元素 。 元素A [i]除以A [i + 1]A [i + 1]除以A [i]

Input:

输入:

Only one line with two integer, n & m respectively.

只有一行包含两个整数,分别为nm

Output:

输出:

Print number of different possible ways to create the array. Since the output could be long take modulo 10^9+7.

打印创建数组的各种可能方式的数量。 由于输出可能很长,取模10 ^ 9 + 7

Constraints:

限制条件:

1<=n, m<=100

Example:

例:

    Input:
n = 3, m = 2.
Output:
8
Explanation:
{1,1,1},{1, 1, 2}, {1, 2, 1},
{1, 2, 2}, {2, 1, 1},
{2,1,2},  {2,2,1}, {2,2,2} are possible arrays.
Input:
n = 1, m = 5.
Output:
5
Explanation:
{1}, {2}, {3}, {4}, {5}

Solution Approach:

解决方法:

The above problem is a great example of recursion. What can be the recursive function and how we can formulate.

上面的问题是递归的一个很好的例子。 什么是递归函数,以及我们如何公式化。

Say,

说,

Let

F(n, m) = number of ways for array size n and range 1 to m

F(n,m) =数组大小为n且范围为1到m的路径数

Now,

现在,

We actually can try picking every element from raging 1 to m and try recurring for other elements

实际上,我们可以尝试从1m范围内选取每个元素,然后尝试对其他元素进行重复

So, the function can be written like:

因此,该函数可以这样写:

Function: NumberofWays(cur_index,lastelement,n,m)

So, to describe the arguments,

因此,为了描述这些论点,

cur_index is your current index and the last element is the previous index value assigned. So basically need to check which value with range 1 to m fits in the cur_index such that the divisibility constraint satisfies.

cur_index是当前索引,最后一个元素是分配的前一个索引值。 因此,基本上需要检查范围在1到m之间的哪个值适合cur_index ,以便除数约束满足。

So, to describe the body of the function

因此,要描述功能的主体

Function NumberofWays(cur_index,lastelement,n,m)
// formed the array completely
if(cur_index==n)
return 1;
sum=0
// any element in the range
for j=1 to m
// if divisible then lastelement,
// j can be adjacent pair
if(j%lastelement==0 || lastelement%j==0)
// recur for rest of the elments
sum=(sum%MOD+ NumberofWays(cur_index+1,j,n,m)%MOD)%MOD;
end if
end for
End function

Now the above recursive function generates many overlapping sub-problem and that's why we use the top-down DP approach to store already computed sub-problem results.
Below is the implementation with adding memoization.

现在,上面的递归函数会生成许多重叠的子问题,这就是为什么我们使用自上而下的DP方法来存储已经计算出的子问题结果的原因。
下面是添加备忘录的实现。

Initiate a 2D DP array with -1

使用-1启动2D DP阵列

Function NumberofWays(cur_index,lastelement,n,m)
// formed the array completely
if(cur_index==n)
return 1;
// if solution to sub problem already exits
if(dp[cur_index][lastelement]!=-1)
return dpdp[cur_index][lastelement];
sum=0
for j=1 to m // any element in the range
// if divisible then lastelement,j can be adjacent pair
if(j%lastelement==0 || lastelement%j==0)
// recur for rest of the elments
sum=(sum%MOD+ NumberofWays(cur_index+1,j,n,m)%MOD)%MOD;
end if
end for
Dp[curindex][lastelement]=sum
Return Dp[curindex][lastelement]
End function

C++ Implementation:

C ++实现:

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int dp[101][101];
int countarray(int index, int i, int n, int m)
{
// if solution to sub problem already exits
if (dp[index][i] != -1)
return dp[index][i];
if (index == n)
return 1;
int sum = 0;
//any element in the range
for (int j = 1; j <= m; j++) {
// if divisible then i,j can be adjacent pair
if (j % i == 0 || i % j == 0) {
// recur for rest of the elments
sum = (sum % MOD + countarray(index + 1, j, n, m) % MOD) % MOD;
}
}
dp[index][i] = sum;
return dp[index][i];
}
int main()
{
int n, m;
cout << "Enter value of n:\n";
cin >> n;
cout << "Enter value of m:\n";
cin >> m;
// initialize DP matrix
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
dp[i][j] = -1;
}
}
cout << "number of ways are: " << countarray(0, 1, n, m) << endl;
return 0;
}

Output:

输出:

Enter value of n:
3
Enter value of m:
2
number of ways are: 8

翻译自: https://www.includehelp.com/icp/count-of-divisible-array.aspx

vb 导出整数 科学计数法

vb 导出整数 科学计数法_可整数组的计数相关推荐

  1. C语言实例:输出八进制,十进制,十六进制,指定位数整数,带符号整数,科学计数法表示的整数

    C语言实例:输出整数的几种方式 1. 直接输出整数 直接使用printf函数输出整数即可,例如: #include <stdio.h>int main() {int num = 123;p ...

  2. java导出excel 科学计数法_基于Java将Excel科学计数法解析成数字

    需要注意的是一般的科学表达式是 1.8E12 1.8E-12 而在Excel中的科学表达式是 1.8E+12 1.8E-12 我写的科学计数法的正则表达式是 (-?\d+\.?\d*)[Ee]{1}[ ...

  3. js导出科学计数法_怎么让js不自动转换成科学计数法

    2016-03-20 回答 function convertnum(beforecounttest) {       //转换之前的科学计数法表示       var tempvalue = befo ...

  4. javascript number转string不用科学计数法_[JavaScript]之数据类型篇

    JavaScript共有7种数据类型:number,string,boolean,symbol,undefined,null,object 1. number 整数和浮点数 JavaScript 内部 ...

  5. 科学计数法_第一章 科学计数法与近似数

    生活中,我们常常遇到一些较大的数,如10000000.3450000000等.利用科学计数法表示某些较大的数可以免去一些不必要的麻烦,尤其是遇到一些乘法运算时,如20000000×245000000. ...

  6. sql显示结果不要科学计数法_教你一招丨标准平板菌落计数法

    平板菌落计数法,是种统计物品含菌数的有效方法.但许多小伙伴却不能很好地掌握其计算方法,今天,小析姐就为大家整理了标准平板菌落计数法,希望能对小伙伴们有所帮助. 检测食品中微生物数量,一般采用标准平板菌 ...

  7. java double 不用科学计数法_如何使java中double类型不以科学计数法表示

    在java中,把一个double或者BigDecimal的小数转换为字符串时,经常会用科学计数法表示,而我们一般不想使用科学计数法,可以通过: DecimalFormat a = new Decima ...

  8. JS 科学计数法,两大正整数相加

    两大数相加,其结果要求返回数字而非科学计数法. 其一:正整数相加 function handleBigNum(a, b) {var result = '';var num = 0;num1 = num ...

  9. 分类计数原理与分步计数原理_分类计数原理与分步计数原理

    分类计数原理与分步计数原理 <分类计数原理与分步计数原理 ( 一 ) >教学设计 柳州地区民族高级中学 覃艳莉 相关教材 : 人民教育出版社的全日制普通高级中学教科书 ( 必修 ) < ...

最新文章

  1. 大道至简,回归到梦开始的地方。人生如此,编程亦如此。
  2. 欢迎进入 K同学啊 的博客目录(全站式导航)
  3. PL/0语言编译程序分析
  4. TradingView 初识
  5. java文件改成smla,Java base64 转 FileInputStream
  6. Linux网络协议栈:一个TCP链接的耗时
  7. [Swift A] - Using Swift with Cocoa and Objective-C--Mix and Match
  8. JAVA地址连接状态检测工具类
  9. 《实战》基于情感词典的文本情感分析与LDA主题分析
  10. Android Studio插件GsonFormat详解
  11. Couldn't Copy Base System 错误处理办法
  12. android虚线边框_Android自定义View之绘制虚线
  13. [每日一氵] python string format按照索引ID失效
  14. 详解OpenWrt路由器设置Crontab定时检查网络并重启
  15. Solidity IDE Remix中文版使用手册
  16. C# 发送邮件内容嵌入图片
  17. Git GUI Here 设置成中文界面
  18. 二分查找、分治算法——汉诺塔问题
  19. checkpatch海思SDK代码遇见的常见错误《二》
  20. C语言之复合类型下卷(十九)(自然法则)(2023)

热门文章

  1. 华为python有必要学吗_【华为云技术分享】这个 Python 库有必要好好学学
  2. Docker 容器部署 Consul 集群
  3. layui前端时间戳转化
  4. failed to keep to the max pss of 66560
  5. 使用T-SQL语句操作数据表-删除数据
  6. shell脚本:批量修改文件名(文件名中添加字符)
  7. php脚本超时 结束执行代码
  8. Javascript开发技巧(JS中的变量、运算符、分支结构、循环结构)
  9. 如何部署 Hyperic ,使得从内网监测外网服务器
  10. Delphi利用Windows GDI实现文字倾斜