Helping with problem 10898UVA

Правка en1, от challengersy, 2016-03-11 06:47:50

I am getting WA.this is my code:

include

include<stdio.h>

include

using namespace std; typedef long long ll;

define rep(i,n) for(int i=0;i<n;i++)

define maxn 10000000

define oo (int)6e6

int dp[maxn]; int state[20], prices[20]; int n, m; bool can(int x, int y) { while (x>0 && y > 0) { if ((x % 10) < (y % 10)) return false; x /= 10; y /= 10; } if (x == 0 && y != 0) return false; return true; } int solve(int id) { if (id == 0) return 0; if (id < 0) return oo; if (dp[id] != oo) return dp[id]; int &ret = dp[id]; rep(i, (n + m)) { if (can(id, state[i])) ret = min(ret, solve(id — state[i]) + prices[i]); } return ret; } int main() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); //cout << -1 << endl; while (cin >> n) { rep(i, n) { int sum = 1; rep(j, n — 1 — i) sum *= 10; state[i] = sum; cin >> prices[i]; } //cout << -1 << endl; cin >> m; rep(i, m) { int sum = 0; rep(j, n) { int x; cin >> x; sum = sum * 10 + x; } state[i + n] = sum; cin >> prices[i + n]; } rep(i, maxn) dp[i] = oo; rep(i, n + m) dp[state[i]] = prices[i]; int ts; cin >> ts; while (ts--) { int sum = 0, sum2 = 0; bool arr[7]; rep(j, 7) arr[j] = 0; rep(i, n) { int x; cin >> x; if (x == 10) { arr[i] = 1; sum = sum * 10 + 9; } else sum = sum * 10 + x; } rep(i, n) { if (arr[i]) { int x = 1; rep(j, n — 1 — i) x *= 10; sum2 += x; } } cout << solve(sum) + solve(sum2) << endl; } } } if anybody can help me with critical input?

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский challengersy 2016-03-11 06:49:17 1683
en1 Английский challengersy 2016-03-11 06:47:50 1834 Initial revision (published)