ecnu 1600 DP
来源:互联网 发布:为什么愤青仇恨公知 编辑:程序博客网 时间:2024/05/09 06:09
还可以继续优化,想继续优化见点击打开链接
AC代码如下:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;#define MAX 0x3f3f3f3fstruct Node{ int num; int s[310]; int e[310];};int dp[51][51*600];Node node[51];int N, M;int gettime( char s[] ){ int a = ( s[0] - '0' ) * 10 + s[1] - '0'; int b = ( s[2] - '0' ) * 10 + s[3] - '0'; int c = ( s[4] - '0' ) * 10 + s[5] - '0'; return a * 3600 + b * 60 + c - 6 * 3600;}int outtime( int t ){ t += 6 * 3600; int a = t / 3600; int b = t % 3600 / 60; int c= t % 3600 % 60; if( a < 10 ){ cout << 0; } cout << a; if( b < 10 ){ cout << 0; } cout << b; if( c < 10 ){ cout << 0; } cout << c; return 0;}int main(){ while( scanf( "%d%d", &N, &M ) != EOF ){ memset( node, 0, sizeof( node ) ); for( int i = 0; i < M; i++ ){ int temp1, temp3; char temp2[20]; scanf( "%d%s%d", &temp1, temp2, &temp3 ); node[temp1].s[node[temp1].num] = gettime( temp2 ); node[temp1].e[node[temp1].num] = node[temp1].s[node[temp1].num] + temp3; node[temp1].num++; } memset( dp, -1, sizeof( dp ) ); dp[1][0] = 0; for( int i = 2; i <= N; i++ ){ for( int j = 300 * ( i - 1 ); j <= 600 * ( i - 1 ); j++ ){ for( int t = 300; t <= 600; t++ ){ if( j >= t && dp[i-1][j-t] != -1 ){ int temp = 0; for( int k = 0; k < node[i-1].num; k++ ){ int a = j - t, b = j; int c = node[i-1].s[k]; int d = node[i-1].e[k]; if( ( c < a && d > b ) || ( c > a && d < b ) || b == d ){ temp++; } } if( dp[i][j] == -1 ){ dp[i][j] = dp[i-1][j-t] + temp; }else{ dp[i][j] = min( dp[i][j], dp[i-1][j-t] + temp ); } if( dp[i][j] == 0 ){//优化..................... break; } } } } } int ans = MAX; for( int i = ( N - 1 ) * 300; i <= ( N - 1 ) * 600; i++ ){ if( dp[N][i] != -1 ){ ans = min( dp[N][i], ans ); } } int time = 0; for( int i = ( N - 1 ) * 300; i <= ( N - 1 ) * 600; i++ ){ if( dp[N][i] == ans ){ time = i; break; } } cout << ans << endl; outtime( time ); cout << endl; } return 0;}
0 0
- ecnu 1600 DP
- ecnu 1600 公路巡逻 (黑书上的DP)
- ECNU 1600 公路巡逻 (黑书例题,DP)
- ecnu
- ecnu 1244 积木游戏(黑书)DP
- ECNU CCCC选拔赛 E题 Teacher Panda and plagiarism dp
- 多校第七场ECNU 1006 HDU 3905 Sleeping (二维DP)
- ecnu 1244
- ECNU OJ
- ECNU-3260
- ECNU-3263
- ECNU-IP Address 1002
- A. 拼音魔法 ecnu
- ecnu 铁路修复计划
- ECNU 3263 贪心
- ecnu 故事 数学
- ecnu 核反应控制 数学
- ecnu 电话送报 贪心
- c语言中的头文件
- Spring-DI(依赖注入)
- 矩形嵌套(nyoj 16)
- 学习PB知识总结之八---modify()函数的用法
- 当我想你的时候
- ecnu 1600 DP
- Java Executor 框架
- ruby on rails 实践中的一些重要操作
- 黑马程序员——JAVA 面向对象知识点总结(二)
- 小牛成长记--链表学习
- myBatis 动态sql实例
- Ubuntu12.04 vim上安装taglist
- GIT这玩意儿
- 几种排序算法效率的比较