12
返回列表 发新帖
楼主: 徐小桃
跳转到指定楼层
上一主题 下一主题
收起左侧

电面 爱比

🔗
 楼主| 徐小桃 2019-9-23 07:10:52 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies

评分

参与人数 2大米 +2 收起 理由
fish19911231 + 1 禁止公开留微信、邮箱或者拉群
iriswei + 1 赞一个

查看全部评分

回复

使用道具 举报

🔗
 楼主| 徐小桃 2019-9-23 07:11:06 | 只看该作者
全局:
iriswei 发表于 2019-9-23 06:56
马上要面abb了,求群主指点下,拜托了🙏

看最新的回复
回复

使用道具 举报

全局:
楼主我真的是把能加米都给你了,**逼只能每次+1
谢谢谢谢!
回复

使用道具 举报

🔗
zhoujy 2019-9-23 12:20:50 | 只看该作者
全局:
一个带记忆的dfs的做法,先把所有experiences 按照end time排序dp(k,duration), 代表从前k个里选若干experience, 这些experience在duration (in hours) 范围内,欢迎一起讨论。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class Solution {
  4. public:
  5.     vector<vector<int>> memo;
  6.     int dp(vector<vector<int>>& experiences,int k,int duration){
  7.         int start = experiences[k][0];
  8.         int end = experiences[k][1];
  9.         int interest = experiences[k][2];
  10.         if(k==0) {
  11.             if(end-start<=duration) return interest;
  12.             return 0;
  13.         }
  14.         if(duration<=0) return 0;
  15.         if(memo[k][duration]) return memo[k][duration];
  16.         memo[k][duration] = dp(experiences,k-1,duration);
  17.         if(end-start<=duration) {
  18.             memo[k][duration] = max(memo[k][duration],interest);
  19.             for(int i = k-1;i>=0;i--){
  20.                 if(experiences[i][1]<=start){
  21.                     memo[k][duration] = max(memo[k][duration],interest+dp(experiences,i,duration-(end-experiences[i][1])));
  22.                 }
  23.             }
  24.         }
  25.         return memo[k][duration];
  26.     }
  27.     static bool comp(vector<int>& a,vector<int>&b){
  28.         return a[2]<b[2];
  29.     }
  30.     int maxInterest(vector<vector<int>> experiences){
  31.         // sort experience by end date in ascending order
  32.         sort(experiences.begin(),experiences.end(),comp);
  33.         int n = experiences.size();
  34.         memo.resize(n,vector<int>(25,0));
  35.         return dp(experiences,n-1,24);
  36.     }
  37. };

  38. int main(){
  39.     Solution s;
  40.     vector<vector<int>> experiences({{0,5,5},{6,8,12},{0,3,1}});
  41.     cout<<s.maxInterest(experiences);
  42. }   
复制代码
回复

使用道具 举报

🔗
zhimingli123 2019-9-23 12:50:59 | 只看该作者
全局:
徐小桃 发表于 2019-9-23 07:10
时间有点久了但我记得我是这样做的
dp代表的是在时间i时能选的最大interest数 因为是1天的时间所以可以a ...

时间复杂不是nlogn吗因为得用sort?请问是怎么做到n的啊
回复

使用道具 举报

🔗
 楼主| 徐小桃 2019-9-23 13:21:09 来自APP | 只看该作者
全局:
zhimingli123 发表于 2019/09/23 12:50:59
时间复杂不是nlogn吗因为得用sort?请问是怎么做到n的啊
不算sort的话 因为之前那个人说是n方 这里只是解释一下不是n方
回复

使用道具 举报

🔗
HanBurger 2019-9-24 06:47:26 | 只看该作者
全局:
楼主店面大概多久又回复的呀
回复

使用道具 举报

🔗
 楼主| 徐小桃 2019-9-25 13:49:01 | 只看该作者
全局:
HanBurger 发表于 2019-9-24 06:47
楼主店面大概多久又回复的呀

他们家 我大概都是等了2到3个工作日才有消息的
回复

使用道具 举报

🔗
Happy-zyy 2019-10-7 20:47:41 | 只看该作者
全局:
贴一下自己的代码,但这个时间复杂度是O(nk),其中n是item数量,k是最大时间

  1. def fun(l):
  2.     l = sorted(l, key=lambda x:x[1])
  3.     n = (l[-1][1] + 1)
  4.     dp = [0] * n
  5.     path = [-1] * n
  6.     for k,e in enumerate(l):
  7.         interest = max(dp[e[1]], dp[e[0]] + e[2])
  8.         for i in range(e[1],n):
  9.             if interest > dp[i]:
  10.                 path[i] = k
  11.                 dp[i] = interest

  12.     ans = []
  13.     j = n - 1
  14.     while path[j] != -1:
  15.         ans.append(l[path[j]])
  16.         j = dp[j-l[path[j]][2]]

  17.     print(ans)
  18.     return dp[n-1]


  19. a = [[6, 18, 2],[0, 3, 1], [0, 5, 5]]
  20. print(fun(a))


  21. #[[0, 5, 5], [6, 18, 2]]
  22. #7
复制代码
回复

使用道具 举报

🔗
sssssC 2019-10-30 09:54:04 | 只看该作者
全局:
感觉这一题也好像可以不sort直接用map存(endTime, indexes of experiences ending at endTime) 然后再traverse 0 - 23 每个check一下map然后update dp[i]的最大interest, 这样的话times是O(n) (存map用n, traverse update dp是O(1)) 不过就是用了个extra space
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表