问题陈述 :
在正整数上,您可以执行以下3个步骤中的任何一个.
现在问题是,给定正整数n,找到将n取为1的最小步数
例如:
我知道使用动态编程并具有整数数组的解决方案.这是代码.
public int bottomup(int n) {
//here i am defining an integer array
//Exception is thrown here, if the n values is high.
public int[] bu = new int[n+1];
bu[0] = 0;
bu[1] = 0;
for(int i=2;i<=n;i++) {
int r …Run Code Online (Sandbox Code Playgroud)