1002. Business (35)
来源:互联网 发布:java 获取时间 编辑:程序博客网 时间:2024/06/04 19:03
感想:动态规划真正的入门题,之前搞过一个d'p的但是不是很懂,现在算是理解了动态规划的本质是什么了
代码里有原来傻傻的我写的DFS 的方法,果断超时了。。。。。
另:STL里的map添加不用insert,[]运算符里已经重载了insert了!!被网上的博客骗得好惨
#include<iostream>#include<vector>#include<map>#include<deque>#include<cstdio>#include<string>#include<algorithm>using namespace std;int N;long MAXDAY=-1,MAXFPOFIT=-1;struct bus{long profit;long Day_take;long DDL; bool operator<(bus &a){return DDL<a.DDL;}}b[60];string isread;map<long,int> m1,m2 ;vector<bus> q;/*//TLE 的 DFS void DFS(int i,long day,long pro){if(pro+b[i].profit>MAXFPOFIT)MAXFPOFIT=pro+b[i].profit;isread[i]='1';if(m.find(isread)==m.end()){m.insert(pair<string ,int>(isread,pro+b[i].profit));for(int j=0;j<N;j++){if(isread[j]=='0'&&(day+b[i].Day_take+b[j].Day_take)<=b[j].DDL)DFS(j,day+b[i].Day_take,pro+b[i].profit);}}isread[i]='0';}*/int main(){int i,j,k;map<long,int>::iterator it;cin>>N;for(i=0;i<N;i++){cin>>b[i].profit>>b[i].Day_take>>b[i].DDL;if(b[i].DDL>MAXDAY)MAXDAY=b[i].DDL;isread+='0';}/*for(i=0;i<N;i++)DFS(i,0,0);*/sort(b,b+N);m2[0]=0;for(i=0;i<N;i++){m1=m2;for(it=m1.begin();it!=m1.end();it++){if(it->first+b[i].Day_take<=b[i].DDL){if(it->second+b[i].profit>m2[it->first+b[i].Day_take]){m2[it->first+b[i].Day_take]=it->second+b[i].profit;if(MAXFPOFIT<m2[it->first+b[i].Day_take])MAXFPOFIT=m2[it->first+b[i].Day_take];}}}} cout<<MAXFPOFIT;}
0 0
- PAT. 1002. Business (35)
- 1002. Business (35)
- PAT 1002. Business (35)
- 1002. Business (35)解题报告
- pat-top 1002. Business (35)
- business
- business
- PAT (Top Level) Practise 1002Business (35)
- Business to Business Negotiation
- Business Letters
- business lunch
- Business Conversation
- Business Plan
- business modeling
- Business Components
- Business Connector
- Business Framework
- Business Object
- python-mysql安装mysqldb模块
- OOAD与UML笔记
- 关于Java Socket编程的详细介绍
- BIOS设置 翻译中文教程
- (net.sf.json) java对象和json对象之间互相转换
- 1002. Business (35)
- CNN常见模型逐层分析(LeNet5 AlexNet VGGNet GoogLeNet)
- 矩阵快速幂题型
- zoj 3469 Food Delivery(区间dp)
- C++中的iostream输入输出
- android sdk编译 提示error: undefined reference to memchr
- jquery效果
- centos下安装JDK
- springMVC的生命周期