shubro18's blog

By shubro18, history, 3 years ago, In English

I submitted a dp solution to problem 996A of Hit The Lottery. I didnt find any error in my code and logic seems to be fine. Can someone tell me why am I getting this error. I am new to CP and would appreciate if the nuances are clearly highlighted to me.

#include<bits/stdc++.h>
using namespace std;
#define min(a,b) ((a<=b)?a:b)
typedef long long ll;
int main()
{
    vector<long long int> v1 = {1, 5, 10, 20, 100};
    long long int n;
    cin>>n;
    vector<long long int> dp(n+1,0);
    dp[0] = 1;
    long long int min;
    for(int i = 1;i<=n;i++)
    {
        min = dp[i - 1] + 1;
        for(auto j:v1)
        {
            if(j<=i&&(dp[i - j]+dp[j]<min))
            {
                min = dp[i - j] + dp[j];
            }
        }
        dp[i] = min;
    }
    cout<<dp[n];
    return 0;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it