blob: acf3693ad52e56fd94b87f671464c121c97c2ef8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#import "html_elements.typ": post
#import "./lib.typ": flex, svg_inline
#show: post
- #link("https://olimpiada.ic.unicamp.br/pratique/ps/2018/f3/muro/")[Enunciado]
Podemos criar uma função recursiva #svg_inline[f]:
#html.frame()[
#text(fill: white)[
$
& f(0) = 1 \
& f(n) = f(n-1) + 4f(n-2) + 2f(n-3) "para" n > 0
$
]
]
Como existem estados que irão se repetir, podemos
usar um vetor para guardar o valor da função já computados.
```cpp
#include <bits/stdc++.h>
#define int long long int
using namespace std;
const int mod = 1e9+7;
const int MAX = 1e4+20;
int dp[MAX]={};
int solve(int pos) {
if(pos==0) return 1;
if(~dp[pos]) return dp[pos];
int ans=0;
ans = (ans+solve(pos-1))%mod;
if(pos>=2) ans = (ans+4*solve(pos-2))%mod;
if(pos>=3) ans = (ans+2*solve(pos-3))%mod;
return dp[pos]=ans;
}
int32_t main() {
memset(dp,-1,sizeof(dp));
int n;
scanf("%lld",&n);
printf("%lld\n",solve(n));
return 0;
}
```
|