题意:给出一个关于参数m矩阵构造方法,矩阵构造出来为(m+1)*(m+1)的,且都为0或1,给出n和t,问1<=m<=n为参数的矩阵中,最后一行的sum恰好为t的数量。
范围:n,t小于10的12次
解法:
首先根据题目给出的构造方法打表,发现前62个数满足:
1 2
1 2 2 4
1 2 2 4 2 4 4 8
1 2 2 4 2 4 4 8 2 4 4 8 4 8 8 16
1 2 2 4 2 4 4 8 2 4 4 8 4 8 8 16 2 4 4 8 4 8 8 16 4 8 8 16 8 16 16 32
很明显,是有规律的,每一行都是上一行+上一行每个数*2放到行末。
然后很有趣的是,还有进一步的规律,如果你仔细观察某一行i,对于2的j次这个值出现的次数为 C[i][j],C是组合数。
那么就简单了,因为10的12次是2的40次,一开始预处理出C数组,并计算得到n所在层数,记为I,那么前I-1行的答案直接累加就好了,最后一行则可递归求解。
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<bitset>
#pragma comment(linker, "/STACK:1024000000,1024000000")
template <class T>
bool scanff(T &ret){ //Faster Input
char c; int sgn; T bit=0.1;