632e:http://codeforces.com/problemset/problem/632/e
Ref: 51023067
Test instructions
Given n values, let you choose the number of K, you can repeat the selection, ask what number can be obtained.
Ideas:
Obviously the smallest value plays a big role, we can subtract this minimum value from each value, use a complete backpack, establish DP "I" to indicate, take I so many values at least how many number. If the value I need is less than or equal to K, then K * min + i is a value we can get, because it is necessary to k* the minimum value (note that we start by cutting the minimum value for each number, to add back).
#include <algorithm>#include<iterator>#include<iostream>#include<cstring>#include<cstdlib>#include<iomanip>#include<bitset>#include<cctype>#include<cstdio>#include<string>#include<vector>#include<stack>#include<cmath>#include<queue>#include<list>#include<map>#include<Set>#include<cassert>using namespacestd;//#pragma GCC optimize (3)//#pragma COMMENT (linker, "/stack:102400000,102400000")//C + +//#pragma GCC diagnostic error "-std=c++11"//#pragma COMMENT (linker, "/stack:200000000")//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")//#pragma GCC optimize ("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations, -fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions, Inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions, no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,- falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,- fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,- fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,ofast,inline,- Fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2 ", 3)#defineLson (L, Mid, RT << 1)#defineRson (mid + 1, R, RT << 1 | 1)#defineDebug (x) cerr << #x << "=" << x << "\ n";#definePB Push_back#definePQ Priority_queuetypedefLong Longll;typedef unsignedLong LongUll;typedef pair<ll, LL >Pll;typedef pair<int,int>Pii;typedef pair<int,pii>P3;//priority_queue<int> Q;//This is a big root heap Q//priority_queue<int,vector<int>,greater<int> >q;//This is a little Gan q#defineFi first#defineSe Second//#define Endl ' \ n '#defineOKC Ios::sync_with_stdio (false); Cin.tie (0)#defineFT (A,B,C) for (int a=b; A <= C;++a)//used to press the line#defineREP (I, J, K) for (int i = j; i < K; ++i)#defineMax3 (A,B,C) max (max (b), c);//Priority_queue<int, Vector<int>, greater<int> >que;Constll mos =0x7FFFFFFF;//2147483647Constll nMOS =0x80000000;//-2147483648Const intINF =0x3f3f3f3f;Constll INFF =0x3f3f3f3f3f3f3f3f;// -//const INT mod = 10007;Const DoubleESP = 1e-8;Const DoublePi=acos (-1.0);Const DoublePhi=0.61803399;//Golden Split PointConst DoubleTphi=0.38196601; template<typename t>inline T read (t&x) {x=0;intf=0;CharCh=GetChar (); while(ch<'0'|| Ch>'9') f|= (ch=='-'), ch=GetChar (); while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); returnx=f?-x:x;}/*-----------------------Showtime----------------------*/ Const intMAXN =1009; inta[maxn],dp[maxn*MAXN];intMain () {intn,k; scanf ("%d%d", &n, &k); for(intI=1; i<=n; i++) scanf ("%d", &A[i]); Sort (a+1, A +1+N); N= Unique (A +1, A +1+n)-(A +1); //debug (n); for(intI=2; i<=n; i++) A[i] = a[i]-a[1]; memset (Dp,inf,sizeof(DP)); dp[0] =0; for(intI=2; i<=n; i++){ for(intJ=a[i]; j<=a[i]*k; J + +) {Dp[j]= Min (Dp[j], Dp[j-a[i]] +1); } } for(intI=0; I<=a[n] * k; i++){ if(Dp[i] <=k) {printf ("%d", a[1] * k +i); }} printf ("\ n"); return 0;}
cf-632e
codeforces-632e thief in a shop full backpack