Bzoj 1974: [Sdoi2010]auction Code Auction (DP)

Source: Internet
Author: User
Tags gcd

at 1, 11, 111 ... Choose a <=8, + 11. (n 1) to spell out all possible ... These number mod p can at most have p, find out the processing of the loops. Then DP is obviously ... the DP (i, j, K) indicates that the first I species has a J, a combination of the number mod p = k, and then a recursive push.  

-----------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long Long ll; const int MAXN = 509;const int MAXM = +;const int MOD = 999911659;const int n = 9;int DP[2][MAXM][MAXN], INV[MAXM], C[MAXN][MAXM], CIR[MAXN];int P, R;ll N, CNT[MAXN];void Gcd (int a, int b, int &d, LL &x, ll &y) {if (!b) {d = A;x = 1;y = 1;} else {GCD (b, a% B, D, y, x);Y-= x * (A/b);}}int _c (ll n, int m) {if (M > N)return 0;int ret = 1;For (ll x = n-m + 1 × <= n; x + +)ret = LL (ret) * (x% mod)% MoD;return LL (ret) * inv[m]% MOD;}void Init () {memset (CNT, 0, sizeof CNT);scanf ("%lld%d", &n, &p);int x = 1 P, sz = 0;While (!cnt[x]) {cir[cnt[x] = ++sz] = x;if (sz >= N)Break ;x = (x * + 1)% P;}if (sz! = N) {ll _n = n-cnt[x] + 1;int _SZ = sz-cnt[x] + 1;if (_SZ > 1)R = p-cir[cnt[x] + (_n% _SZ? _n% _SZ: _SZ)-1];ElseR = p-cir[cnt[x]];for (int i = 0, t = cnt[x]; i < P; i++) if (Cnt[i]) {if (Cnt[i] < T)Cnt[i] = 1;ElseCnt[i] = _n/_SZ + (_SZ > 1 && (_n% _SZ) > Cnt[i]-t);}} else {R = p-x;for (int i = 0; i < P; i++)if (Cnt[i]) cnt[i] = 1;}if (R >= P)R-= P;for (int i = 0, FAC = 1; i < n; i++, FAC = i * FAC% MOD) {int D;ll x, y;GCD (FAC, MOD, D, X, y);Inv[i] = (x + mod)% MoD;}for (int i = 0; i < P; i++)For (int j = 0; J < N; j + +)if (Cnt[i]) c[i][j] = _c (Cnt[i] + j-1, j);}inline void upd (int &x, int t) {if ((x + = t) >= MOD)x-= MOD;}int main () {Init ();int c = 0, p = 1;dp[c][0][0] = 1;for (int i = 0; i < P; i++) if (Cnt[i]) {Swap (c, p);For (int j = 0; J < N; j + +)for (int k = 0; k < P; k++)Dp[c][j][k] = dp[p][j][k];For (int j = 0; J < N; j + +)for (int k = 0; k < P; k++) if (Dp[p][j][k])for (int t = 1; t + j < N; t++)upd (Dp[c][j + t][(k + t * i)% P], LL (Dp[p][j][k]) * C[i][t]% MOD);}int ans = 0;for (int i = 0; i < n; i++)upd (ans, dp[c][i][r]);printf ("%d\n", ans);return 0;}

-----------------------------------------------------------------------

1974: [Sdoi2010]auction Code Auction time limit: ten Sec Memory Limit: + MB
Submit: 263 Solved: 97
[Submit] [Status] [Discuss] Description with Ipig's growing attainments in p++ language, he has formed his own set of complete code libraries. The Pig kingdom wants to participate in the POI children's shoes are scrambling to ask Ipig request code base. Ipig didn't want to give the codebase to all the pigs he wanted, and wanted to give some of the pigs that were both good and willing to pay, so he decided to hold a huge auction. At the auction, all n-pigs will be ipig from low to high, from left to right in a row on the Ipig side. Each piggy has 9 pig coins (with an unclear renminbi exchange rate), starting from the far left, each pig raises a sign in turn, which writes the number of pig coins (an integer between 1 and 9) that you want to pay for the code base. As we all know, if you pay more than the left side of the pig, certainly not get the code base of the dream, so from the second, each pig out of the money is equal to the price of the left pig. Eventually the most money of the piglets will get Ipig code base true line, toward the PKU (Pig Kingdom University) dream forward. Ipig is very satisfied with the idea that he thought of, on the way to the scene, Ipig in the imagination of the auction will appear in the scene, such as a total number of bids, such as the situation, but these questions are too simple, ipig already dared not interested, he wants to study more difficult problems. Ipig found that if he looked down from the stage, all the pig's brand from left to right would be exactly an n-bit integer, and the question he now wanted to challenge was how many of the possible integers could be exactly divisible by P. Because the answer is too big, he just wants to know the answer mod 999911659. Input has and has only one line: two number N (1≤n≤10^18), P (1≤p≤500), separated by a space. Output has and has only one row: A number that represents the remainder of the answer divided by 999911659. Sample Input2 3
Sample Output15
Sample explanation
The scheme can be: 12 15 18 24 27 33 36 39 45 48 57 66 69 78 99, total 15 species.
Data size
Test point NP Test point NP
1≤1000≤5006≤10^6≤500
2≤10^1857≤10^18≤120
3≤10^18≤108≤10^18≤500
4≤10^18≤109≤10^18≤500
5≤10^182510≤10^18≤500
HINT

Source

Sdoi2010 Contest2 Day2

Bzoj 1974: [Sdoi2010]auction Code Auction (DP)

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.