Link: http://acm.bnu.edu.cn/v3/problem_show.php? PID = 1, 4307
It turned out to be a hot-up question for the New Year's North Division competition.
It should be found from the set composed of [0, n-1], including the number of subsets of two consecutive numbers (n-1, 0 can also be.
Train of Thought: Use AA to record the question request, and use BB to record the number of subsets that meet the question condition except (n-1, 0) in [0, n-1. Calculate by recursive method.
When calculating BB [I], there are three situations: 1. subset number BB [I-1]; 2. select the I-1 but not the I-2 of the child set BB [I-2]; 3. select both the I-1 and the number of child POW I-2.
When calculating AA [I], there are four situations: 1. subset number BB [I-1]; 2. select the I-1 and select the number of child sets of the I-2 BB [I-2]; 3. both select the I-1 and select the number of sub-set BB [I-2]; (the first two cases should use the principle of rejection minus the I-2, I-1, 0 at the same time select the situation) 4. select the I-1 but do not select the I-2 and 0.
Code:
#include <iostream>#include <cstdio>using namespace std;#define MOD 8061int aa[1000005],bb[1000005],Pow[1000005];void init(){ Pow[0]=1; for(int i=1;i<=1000000;i++) Pow[i]=(Pow[i-1]*2)%MOD; bb[2]=1; bb[3]=3; aa[2]=1; aa[3]=4; for(int i=4;i<=1000000;i++) { bb[i]=(bb[i-2]+bb[i-1]+Pow[i-2]+MOD)%MOD; aa[i]=(bb[i-1]+Pow[i-2]*2-Pow[i-3]+bb[i-3]+MOD)%MOD; }}int main(){ int a; init(); while(~scanf("%d",&a)) { printf("%d\n",aa[a]); } return 0;}