//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <fstream> #include <cstring> #include <cmath> #include <stack> #include <string> #include <map> #include <set> #include <list> #include <queue> #include <vector> #include <algorithm> #define Max(a,b) (((a) > (b)) ? (a) : (b)) #define Min(a,b) (((a) < (b)) ? (a) : (b)) #define Abs(x) (((x) > 0) ? (x) : (-(x))) #define MOD 1000000007 #define pi acos(-1.0) using namespace std; typedef long long ll ; typedef unsigned long long ull ; typedef unsigned int uint ; typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;} template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e-7 ; const int N = 210 ; const int M = 1100011*2 ; const ll P = 10000000097ll ; const int MAXN = 10900000 ; const int INF = 0x3f3f3f3f ; const int offset = 100 ; int dp[10005]; int n, m, cur; int main() { std::ios::sync_with_stdio(false); int i, j, t, k, u, c, v, p, numCase = 0; while (cin >> m >> n) { memset (dp, 0x3f, sizeof(dp)); dp[0] = 0; for (i = 0; i < n ; ++i) { cin >> c >> k; for (j = 0; j < k; ++j) { for (cur = m; cur >= 0; --cur) { if (cur - c >= 0) { if (dp[cur - c] != INF) { checkmin (dp[cur], dp[cur - c] + 1); } } } } } if (dp[m] == INF) { printf("Naivete\n"); } else { printf("%d\n",dp[m]); } } return 0; } |
Double click to view unformatted code.