戳我看題
吐槽一下這個題的標題和引文和題並沒有關係23333
愚蠢的我一開始看到題想,這是個零一揹包啊
然後做了一半感覺不對勁
揹包在放東西的時候是不區分順序的,也就是1 2和2 1是一樣的
但在本題中1 2和2 1算兩種答案,並且其中一種可能是不適用情況
實質是個dfs,但是把重複情況存儲在數組裏了。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
const int NINF = -99999;
int n,k;
set<int> x;
int dp[105];
int ans;
void solve(int l)
{
if(x.count(l)==1){
dp[l] = 0;
return;
}
if(dp[l-1]==-1) solve(l-1);
if(dp[l-2]==-1) solve(l-2);
if(dp[l-3]==-1) solve(l-3);
dp[l] = dp[l-1]+dp[l-2]+dp[l-3];
}
void init()
{
dp[0] = 1;
if(x.count(1)==0) dp[1] = dp[0];
else dp[1] = 0;
if(x.count(2)==0) dp[2] = dp[1]+dp[0];
else dp[2] = 0;
if(x.count(3)==0) dp[3] = dp[2]+dp[1]+dp[0];
else dp[3] = 0;
}
int main()
{
scanf("%d %d",&n,&k);
int tmp;
for(int i=0;i<k;i++){
scanf("%d",&tmp);
x.insert(tmp);
}
memset(dp,-1,sizeof(dp));
init();
if(n>3){
solve(n);
}
printf("%d\n",dp[n]);
return 0;
}