4.24
TchongS1010C · · 个人记录
4.17考的太好了不总结
先把两场的分数给搞了
|A |B |C |D |E |总 |排 |
|:---:|:---:|:---:|:---:|:--:|:---:|:-:|
|
A.U404848
直接递归,递归公式是
::::
#include <bits/stdc++.h>
using namespace std ;
int t , n ;
double x , ans[10005] ;
double f(int a)
{
if(a == 0) return 1 ;
if(ans[a]) return ans[a] ;
return ans[a] = a / (x + f(a - 1)) ;
}
int main()
{
cin >> t >> x ;
while(t --)
{
cin >> n ;
printf("%.2lf\n" , f(n)) ;
}
return 0 ;
}
B.P10376
递归公式为
| 所以这里的递归公式就非常的合理了 |
|---|
| ```cpp line-numbers |
| #include <bits/stdc++.h> |
| using namespace std ; |
| long long n , a , b , c , ans[200005] ; |
| const long long mod = 1e9 + 7 ; |
| long long dfs(long long x) |
| { |
| if(x <= c) return 1 ; |
| if(ans[x]) return ans[x] ; |
| return ans[x] = (dfs(x - a) + dfs(x - b)) % mod ; |
| } |
| int main() |
| { |
| cin >> n >> a >> b >> c ; |
| cout << dfs(n) ; |
| return 0 ; |
| } |
| ``` |
| # C.P1434 |
| 1. 我们先直接把dfs二维遍历给搞了 |
| 2. 然后用 |
| ```cpp line-numbers |
| #include <bits/stdc++.h> |
| using namespace std ; |
| int r , c , a[105][105] ; |
| int f[105][105] ; |
| int dx[5] = {1 , -1 , 0 , 0} , dy[5] = {0 , 0 , 1 , -1} ; |
| int maxn ; |
| void dfs(int x , int y) |
| { |
| if(f[x][y] > 0) return ; |
| for(int i = 0 ; i < 4 ; i ++) |
| { |
| if(x + dx[i] < 1 |
| if(a[x + dx[i]][y + dy[i]] >= a[x][y]) continue ; |
| dfs(x + dx[i] , y + dy[i]) ; |
| f[x][y] = max(f[x][y] , f[dx[i] + x][dy[i] + y] + 1) ; |
| } |
| } |
| int main() |
| { |
| cin >> r >> c ; |
| for(int i = 1 ; i <= r ; i ++) |
| { |
| for(int j = 1 ; j <= c ; j ++) |
| { |
| cin >> a[i][j] ; |
| } |
| } |
| for(int i = 1 ; i <= r ; i ++) |
| { |
| for(int j = 1 ; j <= c ; j ++) |
| { |
| dfs(i , j) ; |
| } |
| } |
| for(int i = 1 ; i <= r ; i ++) |
| { |
| for(int j = 1 ; j <= c ; j ++) |
| { |
| maxn = max(maxn , f[i][j] + 1) ; |
| } |
| } |
| cout << maxn ; |
| return 0 ; |
| } |
| ``` |
| 错误原因:答案传递狗屁不通。 |
| # D.P5635 |
关于记录状态我们可以short f[10005][10005], |
| $$ |
| f(x,y)=\begin{cases} |
| 1&x=0,y\not=0\ |
| 2&x\not=0,y=0\ |
| f((x+y)\bmod p,((x+y)\bmod p+y)\bmod p)&\texttt{其他}\ |
| \end{cases} |
| $$ |
| ```cpp line-numbers |
| #include <bits/stdc++.h> |
| using namespace std ; |
| short t , p , w , h , f[10005][10005] ; |
| int dfs(int x , int y) |
| { |
| if(f[x][y] == -1) return 3 ; |
| if(f[x][y]) return f[x][y] ; |
| f[x][y] = -1 ; |
| if(x == 0) f[x][y] = 1 ; |
| else if(y == 0) f[x][y] = 2 ; |
| else f[x][y] = dfs((x + y) % p , ((x + y) % p + y) % p) ; |
| return f[x][y] ; |
| } |
| int main() |
| { |
| cin >> t >> p ; |
| while(t--) |
| { |
| cin >> w >> h ; |
| int ans = dfs(w , h) ; |
| if(ans == 3) cout << "error\n" ; |
| else cout << ans << '\n' ; |
| } |
| return 0 ; |
| } |
| ``` |
| 错误原因:想啥呢没有记忆化直接TLE了只A了两个分值为 |
| # E.P2690 |
| 1.我们用三维状态来表示:当前时间,当前位置,当前移动次数,然后我们有两种可能:移动(能够的情况下),不移动,移动的情况下我们就 |
| ```cpp line-numbers lines=9 |
| #include <bits/stdc++.h> |
| using namespace std ; |
| int t , w , a[1005] , f[1005][10][35] ; |
| int dfs(int ti , int pos , int cnt) |
| { |
| if(ti > t) return 0 ; //已经接完了 |
| if(f[ti][pos][cnt] != -1) return f[ti][pos][cnt] ; //走过 |
| int tmp1 = 0 , tmp2 = 0 ; |
| if(cnt < w) tmp1 = dfs(ti + 1 , 3 - pos , cnt + 1) + (3 - pos == a[ti]); //注意,不一定要接到苹果! |
| tmp2 = dfs(ti + 1 , pos , cnt) + (pos == a[ti]); |
| return f[ti][pos][cnt] = max(tmp1 , tmp2) ; |
| } |
| int main() |
| { |
| cin >> t >> w; |
| for(int i = 1 ; i <= t ; i ++) cin >> a[i] ; |
| memset(f , -1 , sizeof(f)) ; |
| cout << dfs(1 , 1 , 0) ; |
| return 0 ; |
| } |
| ``` |