"CF" 259 Div.1 B Little Pony and Harmony Chest

Source: Internet
Author: User

It's also quite interesting to have a status DP topic.

1 /*435B*/2#include <iostream>3#include <string>4#include <map>5#include <queue>6#include <Set>7#include <stack>8#include <vector>9#include <deque>Ten#include <algorithm> One#include <cstdio> A#include <cmath> -#include <ctime> -#include <cstring> the#include <climits> -#include <cctype> -#include <cassert> -#include <functional> +#include <iterator> -#include <iomanip> + using namespacestd; A //#pragma COMMENT (linker, "/stack:102400000,1024000") at  - #defineSTI set<int> - #defineStpii Set<pair<int, int> > - #defineMpii map<int,int> - #defineVI vector<int> - #definePII pair<int,int> in #defineVpii vector<pair<int,int> > - #defineRep (I, A, n) for (int i=a;i<n;++i) to #definePer (i, a, n) for (int i=n-1;i>=a;--i) + #defineCLR Clear - #definePB Push_back the #defineMP Make_pair * #defineFIR First $ #defineSEC SecondPanax Notoginseng #defineAll (x) (x). Begin (), (x). End () - #defineSZ (x) ((int) (x). Size ()) the #defineLson L, Mid, rt<<1 + #defineRson mid+1, R, rt<<1|1 A  the Const intMAXN = $; + intMASK[MAXN]; - BOOLVISIT[MAXN]; $ intP[MAXN]; $ Const intm = -; - Const intN = (1&LT;&LT;M) +5; - Const intINF =0x1f1f1f1f; the intdp[ the][n]; - intpath[ the][n];Wuyi inta[ the]; the  - voidinit () { Wu     intI, j, k =0; -      About      for(i=2; i<maxn; ++i) { $         if(!Visit[i]) { -p[k++] =i; -              for(J=i*i; j<maxn; j+=i) -VISIT[J] =true; A         } +     } the      -      for(i=1; i<maxn; ++i) { $          for(j=0; j<m; ++j) { the             if(I%p[j] = =0) { theMask[i] |= (1<<j); the             } the         } -     } in      the #ifndef Online_judge theprintf"p[%d] =%d\n", M, P[m]); About     #endif the } the  the intMain () { +Ios::sync_with_stdio (false); - #ifndef Online_judge theFreopen ("data.in","R", stdin);BayiFreopen ("Data.out","W", stdout); the     #endif the      - init (); -     intN; the      thescanf"%d", &n); theRep (I,1, n+1) thescanf"%d", &a[i]); -      the     intI, J, K; the     intSt, TMP; the     intMXS =1<< -;94      theMemset (DP,0x1f,sizeof(DP)); thememset (dp[0],0,sizeof(int)*N); the      for(i=1; i<=n; ++i) {98          for(j=0; j<mxs; ++j) { About              for(k=1; k<= -; ++k) { -                 if(J &Mask[k])101                     Continue;102TMP = dp[i-1][J] + ABS (a[i)-k);103St = J |Mask[k];104                 if(Dp[i][st] >tmp) { theDP[I][ST] =tmp;106PATH[I][ST] =K;107                 }108             }109         } the     }111      the     intMN =Int_max, V;113      the      for(j=0; j<mxs; ++j) { the         if(Dp[n][j] <mn) { theMN =Dp[n][j];117v =J;118         }119     } -     121 vi ans;122     123      for(I=n; i>0; --i) {124K =Path[i][v]; the ANS.PB (k);126V ^=Mask[k];127     } -     129      for(i=n-1; i>=0; --i) theprintf"%d", Ans[i]);131Putchar ('\ n'); the     133 #ifndef Online_judge134printf"Time =%d.\n", (int) clock ());135     #endif136     137     return 0;138}

"CF" 259 Div.1 B Little Pony and Harmony Chest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.