Codeforces Round #363 (Div. 2) C Vacations
来源:互联网 发布:达尔朗 知乎 编辑:程序博客网 时间:2024/06/09 19:44
先爆搜一发,tle,然后改成记忆化搜索,就一直wa
http://blog.csdn.net/keyboarderqq/article/details/51960464
看了大佬代码,发现我少写一个状态。。。相比dp,记忆化搜索还是比较好写的,思路也不难。
#include <bits/stdc++.h>using namespace std;const int MAXN = 110;int num[MAXN],n;int dp[MAXN][4];int dfs(int cnt, int pre){ if(cnt == n) return 0; if(dp[cnt][pre] != -1) return dp[cnt][pre]; int ret = 1000; ret = min(ret,dfs(cnt+1,0)+1); for(int i = 1; i <= 2; ++i) { if(i == pre) continue; if(!(i&num[cnt])) continue; ret = min(ret,dfs(cnt+1,i)); } return dp[cnt][pre] = ret;}int main(){ ios::sync_with_stdio(false); cin >>n; memset(dp,-1,sizeof(dp)); for(int i = 0; i < n; ++i) cin >> num[i]; cout << dfs(0,0) << endl; return 0;}
阅读全文
0 0
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2) [C] Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 C (Div. 2) Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2)C. Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2) C Vacations
- Codeforces Round #363 (Div. 2) C. Vacations(DP)
- Codeforces Round #363 (Div. 2) C. Vacations(DP 动态规划)
- Codeforces Round #363 (Div. 2) C. Vacations(DP)
- Codeforces Round #363 (Div. 2) C. Vacations(逻辑运算)
- ****Codeforces Round #363 (Div. 2) C. Vacations(DP 动态规划)
- Codeforces Round #363 (Div. 2) C. Vacations (DP)
- Codeforces Round #363 (Div. 2) C. Vacations 贪心+dp
- Codeforces Round #363 (Div. 2) C. Vacations —— DP
- Codeforces#363 (Div. 2) C.Vacations
- LeetCode-矩阵旋转
- 1064. 朋友数(20)
- RAID--独立冗余磁盘阵列
- Mapping Solr Converter
- (二十二)Animator 源码分析
- Codeforces Round #363 (Div. 2) C Vacations
- 回顾大一·C语言编程11.4(3)(4)+12.1(1)+12.1(2)①②+实验12.1(3)+12.2+12.3
- 丢失libiconv-2.dll解决办法以及无法定位输入点libiconv-2.dll到动态链接库
- git 到gitub中出现的问题
- CCS7.2软/硬件断点设置,精确计算代码运行时间及定时器定时时间验证(适用于C28x芯片)
- mysql 加载本地数据文件
- QEMU 运行ARM Linux Kernel
- Python学习(十四)——面向对象
- Python之time模块的时间戳、时间字符串格式化与转换(13位时间戳)