• Codeforces Round #574 (Div. 2) C. Basketball Exercise


    翻译:

    最后,SIS已经开放了一个篮球场,所以Demid决定举办一个篮球训练课程。有2个⋅𝑛的学生参加了Demid的练习课,他将他们排成两排,大小相同(每排正好有𝑛人)。学生按从左到右的顺序,每一行从1到𝑛编号。


    现在德米德想选一个队去打篮球。他将从左到右选择球员,每个被选中球员的索引(不包括第一个被选中的球员)将严格大于前一个被选中球员的索引。为了避免优先选择某一行,Demid选择学生的方式是,连续选择的学生都不属于同一行。第一个学生可以从所有2名𝑛学生中选择(没有额外的限制),一个团队可以由任意数量的学生组成。

    Demid认为,为了组成一个完美的团队,他应该这样选择学生,所有被选的学生的总身高是尽可能大的。帮助Demid找到他可以选择的队伍中球员的最大可能的总身高。

    输入
    输入的第一行包含单个整数𝑛(1≤𝑛≤105)——每一行的学生人数。

    第二行输入包含𝑛整数ℎ1,1,ℎ1,2,…,ℎ1,𝑛(1≤ℎ1,𝑖≤109),ℎ1,𝑖𝑖-th学生的高度在第一行。

    第三行输入包含𝑛整数ℎ2 1,ℎ2,2,…,ℎ2,𝑛(1≤ℎ2,𝑖≤109),ℎ2,𝑖𝑖-th学生的高度在第二行。

    输出
    打印一个整数——Demid可以选择的队伍中球员的最大可能总身高。

    例子
    inputCopy
    5
    9 3 5 7 3
    5 8 1 4 5
    outputCopy
    29
    inputCopy
    3.
    1 2 9
    10 1 1
    outputCopy
    19
    inputCopy
    1
    7
    4
    outputCopy
    7
    请注意
    在第一个例子中,Demid可以选择如下的团队:


    在第二个例子中,Demid可以选择如下的团队:

    思路:

    动态规划,状态转移,当前的由同一行的上一个转移而来,或者由另一行的上个加上当前的。

    代码:

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. #include
    10. #include
    11. #include
    12. #include
    13. #include
    14. using namespace::std;
    15. typedef long long ll;
    16. inline __int128 read(){
    17. __int128 x = 0, f = 1;
    18. char ch = getchar();
    19. while(ch < '0' || ch > '9'){
    20. if(ch == '-')
    21. f = -1;
    22. ch = getchar();
    23. }
    24. while(ch >= '0' && ch <= '9'){
    25. x = x * 10 + ch - '0';
    26. ch = getchar();
    27. }
    28. return x * f;
    29. }
    30. inline void print(__int128 x){
    31. if(x < 0){
    32. putchar('-');
    33. x = -x;
    34. }
    35. if(x > 9)
    36. print(x / 10);
    37. putchar(x % 10 + '0');
    38. }
    39. int n;
    40. ll a[100005],b[100005];
    41. ll dp[100005][2];
    42. int main(){
    43. ios::sync_with_stdio(false);
    44. cin.tie(); cout.tie();
    45. cin>>n;
    46. for (int i =1; i<=n; i++) {
    47. cin>>a[i];
    48. }
    49. for (int i =1; i<=n; i++) {
    50. cin>>b[i];
    51. }
    52. for (int i=1; i<=n; i++) {
    53. dp[i][0]=max(dp[i-1][0],dp[i-1][1]+a[i]);
    54. dp[i][1]=max(dp[i-1][1],dp[i-1][0]+b[i]);
    55. }
    56. printf("%lld\n",max(dp[n][1], dp[n][0]));
    57. return 0;
    58. }

  • 相关阅读:
    Spring学习第6篇: 基于注解使用IOC
    lenovo联想笔记本电脑ThinkPad X13 AMD Gen2(20XH,20XJ)原装出厂Windows10系统镜像
    Java中的链表
    Vue18 v-for指令 展示列表数据
    如何利用大数据构建用户画像?
    python+ipc+改造过的插线板写一个控制ipc疯狂上下电的脚本
    【视觉高级篇】19 # 如何用着色器实现像素动画?
    Vulfocus复现log4j2和vulhub复现log4j2(CVE-2021-44228)
    vue3学习笔记
    OnionArch - 如何实现更新指定字段的通用Handler
  • 原文地址:https://blog.csdn.net/weixin_63555280/article/details/128107437