CSES - Coin Combinations II

Author: Michael Cao

Solution 1

As described in the Unoffical Editorial

Solution 2

This editorial assumes that you've solved Coin Combinations I (which is very similar). If not, the editorial can be found here. For this problem, we'll use the same state and transitions.

Dealing with Ordered Ways

To only count ordered ways, we switch the order of the loops. Since we loop over the coins before the weights in the dp array, it's impossible to create two combinations with the same coins ordered differently, because the order that we update the weights using the coins is the order we loop over them.

C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!