小编DHS*_*DHS的帖子

找到所有排列以获得给定的总和(硬币找零问题)

我正在尝试解决经典的硬币找零(动态)问题。
为了使用动态方法找到所有独特组合的数量以从无限面额的硬币中获得总和,我使用了以下方法:

/* 
     n - number of coins
     arr[] - coin denominations
     x - total sum
     dp[] - array to store number of combinations at index i.
*/
for (int j = 0; j < n; j++)
     for (int i = 1; i <= x; i++)
          if (arr[j] <= i)
              dp[i] = (long) ((dp[i] + dp[i - arr[j]]) % (1e9 + 7));
Run Code Online (Sandbox Code Playgroud)

这给了我所有唯一可能的combinations计数:
例如:

Input:
n=3 x=9
Coins: 2 3 5

Output:
3
Run Code Online (Sandbox Code Playgroud)

到目前为止,一切都很好。但我观察到,只需交换上面代码片段中的循环,我就得到了所有可能的结果permutations

Input:
n=3 …
Run Code Online (Sandbox Code Playgroud)

java puzzle algorithm dynamic-programming coin-change

7
推荐指数
1
解决办法
3490
查看次数

git 删除重复的远程 URL

我正在使用此方法添加多个远程存储库 URL。我错误地使用此命令两次添加了相同的远程网址:

git remote set-url origin --push --add <a remote>
Run Code Online (Sandbox Code Playgroud)

所以现在git remote -v显示这个:

origin  https://github.com/<user>/<repo>.git (fetch)
origin  https://github.com/<user>/<repo>.git (push) // remote-1
origin  https://github.com/<user>/<repo>.git (push) // duplicate reference to same remote-1
origin  https://bitbucket.com/<user>/<repo>.git (push) // remote-2 
Run Code Online (Sandbox Code Playgroud)

所以现在,每当我推送时,git 都会推送 3 次,假设有 3 个 URL。
我如何删除这个重复的 URL,同时保留原始的和新的远程引用。

git

2
推荐指数
1
解决办法
791
查看次数

标签 统计

algorithm ×1

coin-change ×1

dynamic-programming ×1

git ×1

java ×1

puzzle ×1