Problem p00106 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

struct UnionFind {
  vector<int> v;
  UnionFind(int n) : v(n) {
    for (int i = 0; i < n; i++)
      v[i] = i;
  }
  int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
  void unite(int x, int y) { v[find(x)] = find(y); }
};
int price[51];
vector<pair<int, int>> soba;
int dfs(int n) {
  int mi = 10000;
  if (n == 0)
    return 0;
  REP(i, 6) {
    if (n - soba[i].first == 0 || n - soba[i].first >= 200) {
      if (price[(n - soba[i].first) / 100] == 10000)
        mi = min(mi, dfs(n - soba[i].first) + soba[i].second);
      else
        mi = min(mi, price[(n - soba[i].first) / 100] + soba[i].second);
    }
  }
  price[n / 100] = mi;
  return mi;
}
int main() {
  soba.push_back(pair<int, int>(200, 380));   // 1.9
  soba.push_back(pair<int, int>(300, 550));   // 18.3
  soba.push_back(pair<int, int>(500, 850));   // 1.7
  soba.push_back(pair<int, int>(1000, 1520)); // 1.52
  soba.push_back(pair<int, int>(1200, 1870)); // 1.55
  soba.push_back(pair<int, int>(1500, 2244)); // 1.496

  REP(i, 51) { price[i] = 10000; }
  REP(i, 51) { dfs(i * 100); }
  int n;
  while (cin >> n, n) {
    cout << price[n / 100] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

struct UnionFind {
  vector<int> v;
  UnionFind(int n) : v(n) {
    for (int i = 0; i < n; i++)
      v[i] = i;
  }
  int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
  void unite(int x, int y) { v[find(x)] = find(y); }
};
vector<pair<int, int>> soba;
int dfs(int n) {
  int mi = 10000;
  if (n == 0)
    return 0;
  REP(i, 6) {
    if (n - soba[i].first == 0 || n - soba[i].first >= 200)
      mi = min(mi, dfs(n - soba[i].first) + soba[i].second);
  }
  return mi;
}
int main() {

  soba.push_back(pair<int, int>(200, 380));   // 1.9
  soba.push_back(pair<int, int>(300, 550));   // 18.3
  soba.push_back(pair<int, int>(500, 850));   // 1.7
  soba.push_back(pair<int, int>(1000, 1520)); // 1.52
  soba.push_back(pair<int, int>(1200, 1870)); // 1.55
  soba.push_back(pair<int, int>(1500, 2244)); // 1.496
  int n;
  while (cin >> n, n) {
    cout << dfs(n) << endl;
    ;
  }
}