Bzoj 3131 Gold Rush

Source: Internet
Author: User

Considering that the things that come out are actually not much ... Make a note of the direct map.

And then, for example, the X-bit count, multiply the case of ceil (X/2) and Trunc (X/2).

Then there is a ai,j=tab[i]*tab[j], asking for the K-big question before the tables.

This can be sorted, then the monotone queue, the state slowly backward push on the line. (Note that ai,j do not have to take a mold to do so, otherwise ...) I don't know how to do it.

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<cmath>#defineMAXN 1000050#defineMoD 1000000007using namespacestd;Long Longn,k,bit[ -],ret=0, a[maxn],tot=0;Long Longans=0; Map<Long Long,Long Long> tab[7],mp;map<pair<Long Long,Long Long,Long Long>Vis;map<Long Long,Long Long>:: iterator it1,it2;structstatus{Long LongP1,P2; Long LongVal; Status (Long LongP1,Long LongP2,Long Longval):p 1 (p1), p2 (p2), Val (val) {} status () {} friendBOOL operator< (ConstStatus &x,ConstStatus &y) {returnx.val<Y.val; }};p Riority_queue<status>Q;BOOLcmpLong LongXLong LongY) {returnX>y;} voidPre_dfs (Long LongNowLong Longret) {    if(now-1) tab[now-1][ret]++; if(now==7)return;  for(Long LongI=1; i<=9; i++) Pre_dfs (now+1, ret*i);}voidGet_bit (Long Longx) {ret=0;  while(x) {bit[++ret]=x%Ten; x/=Ten;}}voidUpdateLong LongRetLong Longx) {    if(!x) {mp[ret]++;return;} if(! (X-1)) { for(Long LongI=1; i<=9; i++) mp[ret*i]++;return;} Long LongL=ceil ((Double) x/2), R=trunc ((Double) x/2);  for(It1=tab[l].begin (); It1!=tab[l].end (); it1++)         for(It2=tab[r].begin (); It2!=tab[r].end (); it2++) Mp[ret* (It1->first) * (It2->first)]+=it1->second*it2->second;}voidDIGIT_DP () { for(Long LongI=1; i<=ret-1; i++) Update (1, i); Long Longrets=1;  for(Long Longi=ret;i>=1; i--)    {         for(Long Longj=1; j<bit[i];j++) Update (RETs*j,i-1); RETs*=Bit[i]; } Mp[rets]++;}intMain () {scanf ("%lld%lld",&n,&k); Pre_dfs (1,1);    Get_bit (n);    DIGIT_DP ();  for(It1=mp.begin (); It1!=mp.end (); it1++)    {        if(!it1->first)Continue; a[++tot]=it1->second; } sort (A+1, a+tot+1, CMP); Q.push (Status (1,1,(Long Long) a[1]*a[1])); Long LongTr=0;  for(Long LongI=1; i<=k;i++) {TR++; Status Now=q.top (); Q.pop (); if(Vis[make_pair (NOW.P1,NOW.P2)]) {i--;Continue;} Ans= (ans+now.val%mod)%mod;vis[make_pair (NOW.P1,NOW.P2)]=1; Q.push (Status (NOW.P1,NOW.P2+1,(Long Long) a[now.p1]*a[now.p2+1])); Q.push (Status (Now.p1+1, NOW.P2, (Long Long) a[now.p1+1]*A[NOW.P2])); } printf ("%lld\n", ans%MoD); return 0;}

Bzoj 3131 Gold Rush

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.