Problem-solving: 2017 6 provinces joint exam breaking up is a wish

Source: Internet
Author: User

Question Surface

First, consider what is the optimal strategy. In fact, this optimal strategy is one by one from big to small. Because a small one won't and won't affect the big one, it is obviously the best and necessary, so let's enumerate the factor and store it in vector, then we can directly simulate it to get $ 50pts $ (as if I had made water from Grandpa bi's data (?) Resulting in 80 PTS (FOG)

Consider the random press process before reaching $ K $ and set $ exp [I] $ (do not write this in the code, exp is a function in cmath) it also needs to meet the expectation for $ I $ times.

$ Exp [I] =\frac {I} {n} * 1 + \ frac {n-I} {n} * (exp [I] + exp [I + 1] + 1) $

$ \ Frac {I} {n} * 1 $ indicates that this time is correct and it is transferred directly, $ \ frac {n-I} {n} * (exp [I] + exp [I + 1] + 1) $ indicates that the error was reported this time, returns $ exp [I + 1] $ and transfers back $ exp [I] $.

Then, a recursive formula is obtained for simplifying and moving items.

$ Exp [I] = \ frac {(n-I) * (exp [I + 1] + 1)} {I} + 1 $

Remember to multiply $ n! $

 1 #include<cstdio> 2 #include<vector> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 const int N=100005; 7 const long long mod=100003; 8 long long inv[N],lit[N],ex[N]; 9 long long n,k,cnt,ans,facs;10 vector<long long> vc[N];11 void prework()12 {13     facs=inv[0]=inv[1]=1;14     for(int i=2;i<=n;i++)15     {16         facs=facs*i%mod;17         inv[i]=((mod-mod/i)*inv[mod%i])%mod;18     }19 }20 int main()21 {22     scanf("%lld%lld",&n,&k),prework();23     for(int i=1;i<=n;i++)24         scanf("%lld",&lit[i]);25     for(int i=1;i<=n;i++)26         for(int j=i;j<=n;j+=i)27             vc[j].push_back(i);28     for(int i=n;i;i--)29         if(lit[i])30         {31             cnt++;32             for(int j=0;j<(int)vc[i].size();j++)33                 lit[vc[i][j]]^=1;34         }35     if(cnt<=k) 36         printf("%lld",cnt*facs%mod);37     else38     {39         ex[n]=1;40         for(int i=n-1;i>k;i--)41             ex[i]=((n-i)*(ex[i+1]+1)%mod*inv[i]%mod+1)%mod;42         for(int i=1;i<=cnt;i++)43             ans+=ex[i],ans%=mod;44         printf("%lld",(ans+k)*facs%mod);45     }46     return 0;47 }
View code

 

Problem-solving: 2017 6 provinces joint exam breaking up is a wish

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.