HDU6024 Building Shops(DP)
来源:互联网 发布:maven 打包 java 工程 编辑:程序博客网 时间:2024/06/08 05:03
题目链接
题意:
要在N个教室中的一些建造糖果屋,花费为在该教室建造的花费+其右侧未建造糖果的教室到该教室的距离
分析:
直接DP,d[i]表示在该点建造糖果屋的情况下[i..n]所有教室的最小花费
代码:
#define inf 0x3f3f3f3f3f3f3f3f#define maxn 3007ll n, a[maxn], c[maxn];ll b[maxn], d[maxn];ll work(int x) { if (d[x] != -1) return d[x]; if (x == n) return d[x] = 0; d[x] = inf; ll cost = b[c[x]]; for (int j = x + 1; j <= n; j++) { d[x] = min(d[x], work(j) + cost); cost += 0ll + a[c[j]] - a[c[x]]; } return d[x];}int cmp(int i, int j) { return a[i] < a[j];}int main(){ while (~scanf("%lld", &n)) { for (int i = 0; i < n; i++) { scanf("%lld%lld", &a[i], &b[i]); c[i] = i; } memset(d, -1, sizeof d); sort(c, c + n, cmp); work(0); printf("%lld\n", d[0]); }}
阅读全文
0 0
- HDU6024 Building Shops(DP)
- HDU6024-Building Shops-简单DP
- 【HDU6024】Building Shops(简单dp)
- HDU6024-Building Shops
- HDU6024 Building Shops
- HDU6024 Building Shops 2017中国大学生程序设计竞赛
- hdu 6024 Building Shops (DP)
- HDU 6024 Building Shops (DP)
- HDU 6024 Building Shops(DP)
- HDU 6024 Building Shops (简单dp)
- HDU 6024 Building Shops[dp]
- hdu 6024 Building Shops (dp)
- HDU 6024 Building Shops【DP】
- HDU 6024 Building Shops(DP)
- HDU 6024 Building Shops(DP)
- hdu 6024 Building Shops dp
- Building Shops(动态规划)
- 2017女生赛 1002 Building Shops【dp】
- iOS获取网络时间,网络获取时间,也就是现实中的时间
- 项目登陆功能的总体架设
- Python之创建tuple
- QT中的类型转换
- 多重背包 初学篇
- HDU6024 Building Shops(DP)
- [My SQL] 数据处理函数
- js ActiveXObject 调用本地程序
- mysql使用函数查询树形数据
- css3 transform做动画
- adb startservice 启动服务出现异常,安卓4.X
- Futrure模式
- [Kotlin]Kotlin学习笔记(三):Null检查机制及lateinit与by lazy(委托机制)的应用
- io笔记