牛牛即将要参加考试,他学会了填答题卡。
可惜他竖着的答题卡填成了横着的 : (
好奇的他想知道对于 n 道题,每道题 n 个选项的答题卡 ( n * n 的矩阵 ),满足横答题卡和竖答题卡图形一致的方案数有多少种。
注:每道题只能选择一个选项,即 n * n 的矩阵中只能涂黑 n 个空。求横竖对称的方案数。
规律是a[i]=a[i-1]+(i-1)*a[i-2]
至今没想orz
#include<bits/stdc++.h> using namespace std; int n; long long dp[1000086]; int mod=1e9+7; int main() { cin>>n; dp[1]=1; dp[2]=2; dp[3]=4; for(int i=4;i<=n;i++) { dp[i]=(dp[i-1]+(i-1)*dp[i-2])%mod; } cout<<dp[n]<<endl; }