WOJ Your NP has been charged full(普通dp)
来源:互联网 发布:枣想核你在一起 淘宝 编辑:程序博客网 时间:2024/06/13 21:18
题目分析
现场赛看了这道题并没有写,是因为队友说的题意我理解多了,本来是一个buff三回合之后就没有了,但是我认为只要加上了一个buff那么久一直有这个buff,想dp方程的时候发现有后效性,然后就写不出来了。回来之后重新读题发现一个buff三回合之后消失,那么很明显我们就可以只需知道这回合,上回合以及上上回合选什么buff,然后就可以直接写状态转移方程了,时间复杂度
O(n∗33) 。这里我的dp[i][j][k]表示到底i个回合,这个回合选第j个buff,上个回合选第k个buff。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1e4+100;double a[maxn][4], dp[maxn][4][4];double solve(int id, int _a, int _b, int _c){ double tot[4]; tot[1] = tot[2] = tot[3] = 1.0; tot[_a] += a[id][_a]; tot[_b] += a[id-1][_b]; tot[_c] += a[id-2][_c]; return tot[1]*tot[2]*tot[3];}int main(){ int n; while(scanf("%d", &n) != EOF){ memset(a, 0, sizeof(a)); memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++) for(int j = 1; j <= 3; j++) scanf("%lf", &a[i][j]); for(int i = 1; i <= 3; i++) for(int j = 1; j <= 3; j++) if(i == j) dp[2][i][j] = (1.0+a[1][j])+(1.0+a[1][j]+a[2][i]); else dp[2][i][j] = (1.0+a[1][j]) + (1.0+a[1][j])*(1.0+a[2][i]); for(int i = 3; i <= n; i++){ for(int aa = 1; aa <= 3; aa++){ for(int bb = 1; bb <= 3; bb++){ for(int cc = 1; cc <= 3; cc++){ dp[i][aa][bb] = max(dp[i][aa][bb], dp[i-1][bb][cc] + solve(i, aa, bb, cc)); } } } } double ans = 0; for(int i = 1; i <= 3; i++) for(int j = 1; j <= 3; j++) ans = max(ans, dp[n][i][j]); printf("%.6lf\n", ans); } return 0;}
0 0
- WOJ Your NP has been charged full(普通dp)
- 武大校赛-Your NP has been charged full
- Your account has been blocked
- git Your account has been blocked
- git Your account has been blocked
- [P2P'10] Your paper #1569310503 has been accepted
- There has been an error processing your request magento
- Magento提示“There has been an error processing your request”
- 解决Your iOS Development certificate has been revoked.
- 0x0000007B:A problem has been detected and windows has been shut down to prevent damage to your Comp
- A problem has been detected and windows has been shut down to prevent damage to your computer.
- woj 1049 dp
- hdu 2697 WOJ dp
- WOJ 1608 状压dp
- WOJ-29 Werewolf(DP)
- 安装apache 时出现your system has not been modified的终极解决办法!
- The maximum report processing jobs limit configured by your system administrator has been reached
- magento 的错误:Invalid URI supplied 或 There has been an error processing your request
- SercureCrt默认windows -->config位置
- 【搜索】洛谷 P1025 数的划分
- 【递归】洛谷 P1028 数的计算
- 【2017.4.23】时域展开法 Matlab+opencv
- 获取table表格每行每列的数据
- WOJ Your NP has been charged full(普通dp)
- ftp实现文件上传(下载)
- Radar Installation POJ
- 第三方支付分类方式综述
- 【枚举】洛谷 P1029 最大公约数和最小公倍数问题
- 采用IntentService进行多图片上传处理(包含相册的多图片的选择)
- 物资调度
- 计算机网络部分的面试常考点
- LabVIEW_USB_I2C_AM2321B