2018
T1 paved roads
A differential water problem, push conclusion just fine.
#include<cstdio> #include<algorithm> using namespace std; int a[100005],d[100005],ansz,ansf; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]),d[i]=a[i]-a[i-1]; for(int i=1;i<=n;i++) { if(d[i]<0) ansf-=d[i]; else ansz+=d[i]; } printf("%d\n",max(ansz,ansf)); return 0; }
T2 monetary system
I thought it was a math problem, and later found to dp, very interesting full backpack simple deformation.
Each number of the memory array subscript f, true represents has occurred, false indicates not be represented.
Initialization f [0] to true.
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,a[205],f[25005],T; int main() { scanf("%d",&T); while(T--) { int years = 0 , maxn = 0 ; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]),maxn=max(maxn,a[i]); sort(a+1,a+1+n); memset(f,0,sizeof(f)); f [ 0 ] = to true ; // subscript f represents the number of whether there is excessive for ( int I = . 1 ; I <= n-; I ++ ) { IF (F [A [I]]) continue ; // if too continue appears ANS ++; // default not out for ( int J = A [I]; J <= MAXN; J ++ ) F [j] = max (F [ja [i]], F [j]); // if ja [i] occurred, can guarantee that j can occur, which is a true transfer of assignment } printf("%d\n",ans); } return 0; }