Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5794
Multi-school This problem to transform the model with the CF560E basic, you can do the CF on the problem first.
The topic asks you to ask a pawn to start at (a), can walk like a horse and go to the lower right, do not pass through the bad point, how many kinds of way can reach (n,m) point.
For example, N=6, M=5 has two bad points, the model is converted as:
After converting to a simple model, simply deposit the bad points that may pass through the pieces into the structure, sorted by x and Y from small to large.
Dp[i] represents the number of scenarios from the starting point to the I-I bad point and not through other bad points.
Dp[i] = Lucas (X[i], y[i])-SUM (Dp[j]*lucas (X[i]-x[j], y[i]-x[j]), X[j] <= x[i] && y[j] <= y[i]//To I point all paths Number-number of paths through other points
Then we set the last point to a bad point, like Dp[final], then dp[final] is the answer.
1 //#pragma COMMENT (linker, "/stack:102400000, 102400000")2#include <algorithm>3#include <iostream>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <cmath>9#include <ctime>Ten#include <list> One#include <Set> A#include <map> - using namespacestd; -typedefLong LongLL; thetypedef pair <LL, ll>P; - Const intN = 1e2 +5; - ConstLL mod =110119; - structData { + LL x, y; - BOOL operator< (Constdata& CMP)Const { + returnx = = cmp.x? Y < Cmp.y:x <cmp.x; A } at }q[n]; -LL F[mod +5];//factorial - Dp[n]; - - ll Pow (ll A, ll N, ll MoD) { -LL res =1; in while(n) { - if(N &1) tores = res * A%MoD; +A = a * a%MoD; -N >>=1; the } * returnRes; $ }Panax Notoginseng - ll Comb (ll A, ll B, ll MoD) { the if(A <b) { + return 0; A } the if(A = =b) { + return 1; - } $ return(F[a] * Pow (f[a-b]*f[b]% mod, mod-2, MoD))% MoD;//multiplication Inverse element $ } - - ll Lucas (ll N, ll M, ll MoD) { theLL ans =1; - while(M && N &&ans) {WuyiAns = (ans * Comb (n mod, m% mod, MoD))%MoD; theN/=MoD; -M/=MoD; Wu } - returnans; About } $ - BOOLJudge (ll X, ll y) {//judging the ' horse ' can go to the bad point - if(X >y) - swap (x, y); ALL Dec = y-x; + if(Dec > x | | dec*2> y | | (X-DEC)%3!=0|| (y-dec*2) %3!=0|| X-dec! = y-dec*2) the return true; - return false; $ } the thePGet(ll X, ll y) {//get the Model X and Y the P Res; the if(X >y) { -LL Dec = x-y; inRes.first = Dec, Res.second =0; theX-= Dec *2, Y-=Dec; theRes.first + = x/3, Res.second + = y/3; About}Else { theLL Dec = y-x; theRes.first =0, Res.second =Dec; theX-= Dec, y-= Dec *2; +Res.first + = x/3, Res.second + = y/3; - } the returnRes;Bayi } the the intMain () - { - intCase =1; the LL N, m; the intK; thef[0] =1; the for(LL i =1; I <= mod; ++i) -F[i] = f[i-1] * I%MoD; the while(SCANF ("%lld%lld%d", &n, &m, &k)! =EOF) { theN--, m--; the for(inti =1; I <= K; ++i) {94scanf"%lld%lld", &q[i].x, &q[i].y); theq[i].x--, q[i].y--; the } theprintf"Case #%d:", case++);98 if(judge (n, m)) { Aboutprintf"0\n"); - Continue;101 }102P temp =Get(n, m);103n = temp.first, M =Temp.second;104 intindex =0; the for(inti =1; I <= K; ++i) {106 if(judge (q[i].x, q[i].y))107 Continue;108temp =Get(q[i].x, q[i].y);109 if(Temp.first > N | | temp.second >m) the Continue;111q[++index].x = Temp.first, q[index].y =Temp.second; the }113Sort (q +1, q + index +1); theq[++index].x = N, q[index].y =m; theMemset (DP,0,sizeof(DP)); the for(inti =1; I <= index; ++i) {117LL sum =0;118 for(intj =1; J < I; ++j) {119 if(q[i].x >= q[j].x && q[i].y >=q[j].y) { -sum = (sum + dp[j]*lucas (q[i].x-q[j].x-q[j].y + q[i].y, q[i].y-q[j].y, MoD)% MoD)MoD;121 }122 }123Dp[i] = ((Lucas (q[i].x + q[i].y, Q[I].Y, MoD)-sum)% mod + MoD)%MoD;124 } theprintf"%lld\n", Dp[index]);126 }127 return 0; -}
View Code
HDU 5794 A Simple Chess (Lucas + DP)