hdu 5115 Dire Wolf【区间DP】
来源:互联网 发布:数据透视表总计 编辑:程序博客网 时间:2024/05/18 03:46
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5115
题意:
有n只狼,每只狼有两种属性,一种攻击力一种附加值,我们没杀一只狼,那么我们受到的伤害值为这只狼的攻击值与它旁边的两只狼的附加值的和,求把所有狼都杀光受到的最小的伤害值。
代码:
#include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex> #include <string> #include <functional> #include <iterator> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <list> #include <bitset> #include <sstream> #include <iomanip> #include <fstream> #include <iostream> #include <ctime> #include <cmath> #include <cstring> #include <cstdio> #include <time.h> #include <ctype.h> #include <string.h> #include <assert.h> using namespace std;int n;int a[500],b[500],dp[500][500];int main(){ int t, cases = 1; scanf("%d",&t); while (t--) { scanf("%d",&n); for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = 100000000; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); for (int i = 1; i <= n; i++) dp[i][i] = a[i] + b[i - 1] + b[i + 1]; for (int l = 1; l <= n; l++) { for (int i = 1; i + l <= n; i++) { int j = i + l; dp[i][j] = min(dp[i+1][j] + b[i-1] + b[j+1] + a[i], dp[i][j-1] + a[j] + b[j + 1] + b[i-1]); for (int k = i+1; k <= j; k++) { dp[i][j] = min(dp[i][j], dp[i][k - 1] + dp[k + 1][j] + a[k] + b[i - 1] + b[j + 1]); } } } printf("Case #%d: %d\n", cases++, dp[1][n]); } return 0;}
0 0
- 【DP】 HDU 5115 Dire Wolf 区间DP
- hdu 5115 Dire Wolf 区间DP
- hdu 5115 Dire Wolf (区间DP)
- HDU 5115 Dire Wolf (区间DP)
- hdu 5115 Dire Wolf(区间DP)
- HDU 5115Dire Wolf(区间dp)
- hdu 5115 Dire Wolf【区间DP】
- HDU 5115 Dire Wolf(区间DP)
- HDU 5115 Dire Wolf (区间dp)
- HDU 5115 Dire Wolf(区间DP)
- HDU 5115 Dire Wolf(区间DP)
- HDU - 5115 Dire Wolf(区间DP)
- HDU 5115 Dire Wolf(区间DP)
- hdu 5115 Dire Wolf(区间dp)
- HDU 5115:Dire Wolf 区间dp
- HDU 5115 Dire Wolf(区间DP)
- hdu 5115 Dire Wolf【区间dp】
- HDU 5115 Dire Wolf(区间DP)
- uestc 94(区间更新)
- wampserver环境下配置phpmyadmin远程访问mysql数据库
- optional
- 欢迎使用Markdown编辑器写博客
- Gym 100418J Lucky tickets(数位dp)
- hdu 5115 Dire Wolf【区间DP】
- LeetCode Binary Tree Inorder Traversal
- 一个jsp站的用户密码解密
- 三种主流web服务实现
- control_flow
- loop
- String
- 07-collection
- 08-func