ram_0001's blog

By ram_0001, history, 5 years ago, In English

problem: CSES coin combinations I Link: https://cses.fi/problemset/task/1635 My code:

include<bits/stdc++.h>

using namespace std; int mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,x; cin >> n >> x; vector coins(n); for (int i = 0; i < n;i++) cin >> coins[i]; vector dp(x + 1, 0); dp[0] = 1; for (int i = 1; i <= x;i++){ for (auto j : coins){ if(i-j>=0) dp[i] = (dp[i] + dp[i — j])%mod; } } cout << dp[x]; return 0; }

  • Vote: I like it
  • -6
  • Vote: I do not like it

| Write comment?
»
5 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As the bounds are quite large, try to avoid using vectors and use arrays instead.

Also, next time you should put your code in code blocks like this

#include <iostream>
cin>>a;
cout<<a;

or just link us to your submission

»
5 years ago, hide # |
← Rev. 2  
Vote: I like it 0 Vote: I do not like it

give ur code like this on codeforces blogs and comments

Code