Codeforces 750D 记忆化搜索
来源:互联网 发布:网狐三网通源码 编辑:程序博客网 时间:2024/04/28 20:59
One tradition of welcoming the New Year is launching fireworks into the sky. Usually a launched firework flies vertically upward for some period of time, then explodes, splitting into several parts flying in different directions. Sometimes those parts also explode after some period of time, splitting into even more parts, and so on.
Limak, who lives in an infinite grid, has a single firework. The behaviour of the firework is described with a recursion depth n and a duration for each level of recursion t1, t2, ..., tn. Once Limak launches the firework in some cell, the firework starts moving upward. After covering t1 cells (including the starting cell), it explodes and splits into two parts, each moving in the direction changed by 45 degrees (see the pictures below for clarification). So, one part moves in the top-left direction, while the other one moves in the top-right direction. Each part explodes again after covering t2 cells, splitting into two parts moving in directions again changed by 45 degrees. The process continues till the n-th level of recursion, when all 2n - 1 existing parts explode and disappear without creating new parts. After a few levels of recursion, it's possible that some parts will be at the same place and at the same time — it is allowed and such parts do not crash.
Before launching the firework, Limak must make sure that nobody stands in cells which will be visited at least once by the firework. Can you count the number of those cells?
The first line of the input contains a single integer n (1 ≤ n ≤ 30) — the total depth of the recursion.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 5). On the i-th level each of 2i - 1 parts will cover ti cells before exploding.
Print one integer, denoting the number of cells which will be visited at least once by any part of the firework.
44 2 2 3
39
61 1 1 1 1 3
85
13
3
For the first sample, the drawings below show the situation after each level of recursion. Limak launched the firework from the bottom-most red cell. It covered t1 = 4 cells (marked red), exploded and divided into two parts (their further movement is marked green). All explosions are marked with an 'X' character. On the last drawing, there are 4 red, 4 green, 8 orange and 23 pink cells. So, the total number of visited cells is 4 + 4 + 8 + 23 = 39.
For the second sample, the drawings below show the situation after levels 4, 5 and 6. The middle drawing shows directions of all parts that will move in the next level.
题意:放烟花 每个烟花在经过a[i]个格子后会爆炸 分成两个子烟花 方向分别顺时针和逆时针旋转45度 求经过的总格子数
题解:每个烟花最多延伸5个格子 那么30个烟花最多延伸150个格子 所以染色到的格子最大不超过400*400 而2^30约等于10^9
10^9>>400*400 所以会有很多重复计算 这时候只要记忆化搜索就行了
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[405][405],b[32][400][400][8];int dx[8]={1,1,0,-1,-1,-1,0,1},dy[8]={0,1,1,1,0,-1,-1,-1};int main(){int n,i,t=0,d,x,y,z,dd,xx,yy;b[1][200][200][0]=1;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d",&d);for(x=0;x<400;x++){for(y=0;y<400;y++){for(z=0;z<8;z++){if(b[i][x][y][z]){for(dd=0,xx=x,yy=y;dd<d;dd++){xx+=dx[z],yy+=dy[z];if(!a[xx][yy])t++;5a[xx][yy]=1;}b[i+1][xx][yy][(z+1)&7]=b[i+1][xx][yy][(z+7)&7]=1;}}}}}printf("%d\n",t);return 0;}
- Codeforces 750D 记忆化搜索
- codeforces 118D 记忆搜索
- CodeForces 55D 数位统计 记忆化搜索
- codeforces 148D 概率dp 记忆化搜索
- Codeforces Round #208 (Div. 2) D(记忆化搜索)
- Codeforces 401D Roman and Numbers(记忆化搜索)
- codeforces round #266 D Increase Sequence 记忆化搜索
- Codeforces 486 D Valid Sets 记忆化搜索
- Codeforces #337(Div.2)D. Zuma【记忆化搜索】
- Codeforces 793D Presents in Bankopolis【Dp+记忆化搜索】
- Codeforces Round #427 (Div. 2)-D(记忆化搜索)
- Codeforces 284D Cow Program【思维+记忆化搜索】
- codeforces 82D Two out of Three DP 记忆化搜索
- Codeforces Round #224 (Div. 2) D 暴力搜索加记忆化
- Codeforces Div.301D Bad Luck Island(概率dp+记忆化搜索)
- Codeforces Round #174 (Div. 2)---D. Cow Program(dp, 记忆化搜索)
- Codeforces Round #106(Div. 2) 149D. Coloring Brackets 区间DP 记忆化搜索
- CodeForces 149D Coloring Brackets(记忆化搜索区间dp)【多做】
- LeetCode455. Assign Cookies简单的做法
- Vue.js学习系列二 —— vuex学习实践笔记(附DEMO)
- Html手记:标签属性大全
- linux下查找命令
- 记一次python项目的开发
- Codeforces 750D 记忆化搜索
- LeetCode::Two Sum C语言
- Leetcode 54. Spiral Matrix
- Android管理系统状态栏和导航栏
- C语言程序设计进阶 翁恺 第7周编程题
- 标量子查询和内联视图
- ffmpeg extract_mvs.c笔记
- 根据中序和层次遍历序列,构造二叉树
- javascript的解析以及内存原理