P2467-[SDOI2010]地精部落
1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef double db; 5 #define INF 0x3f3f3f3f 6 #define _for(i,a,b) for(int i = (a);i < b;i ++) 7 #define _rep(i,a,b) for(int i = (a);i > b;i --) 8 inline ll read() 9 { 10 ll ans = 0; 11 char ch = getchar(), last = ' '; 12 while(!isdigit(ch)) last = ch, ch = getchar(); 13 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); 14 if(last == '-') ans = -ans; 15 return ans; 16 } 17 inline void write(ll x) 18 { 19 if(x < 0) x = -x, putchar('-'); 20 if(x >= 10) write(x / 10); 21 putchar(x % 10 + '0'); 22 } 23 int n,mod; 24 int dp[2][6002]; 25 int main() 26 { 27 n = read(), mod = read(); 28 dp[0][2] = 1; 29 _for(i,3,n+1) 30 _for(j,2,i+1) 31 dp[i&1][j] = (dp[i&1][j-1]+dp[(i-1)&1][i-j+1])%mod; 32 int rnt = 0; 33 _for(i,2,n+1) 34 rnt = (rnt+dp[n&1][i])%mod; 35 write((rnt<<1)%mod); 36 return 0; 37 }