zoukankan      html  css  js  c++  java
  • Codeforces Round #697 (Div. 3)G. Strange Beauty

    题目大意:给定n个数字,使其成为完美的,定义完美指所有数字之间均有整除关系,问最少删除多少数字使得变完美。

    题目链接

    解题思路:观察到数字大小为2e5,对数字进行计数。dp[i]定义为所选数字为i的因子时的最大数量,所以每次dp,对i的倍数进行更新。

     1 #include<stdio.h>
     2 #include<algorithm>
     3 #include<string.h>
     4 using namespace std;
     5 
     6 typedef long long ll;
     7 const int maxn=2e5+5;
     8 int t,n;
     9 int dp[maxn];
    10 int cnt[maxn];
    11 
    12 int main()
    13 {
    14     int t;
    15     scanf("%d",&t);
    16     while(t--)
    17     {
    18         memset(cnt,0,sizeof(cnt));
    19         memset(dp,0,sizeof(dp));
    20         scanf("%d",&n);
    21         for(int i=1;i<=n;i++){
    22             int tmp;
    23             scanf("%d",&tmp);
    24             cnt[tmp]++;
    25         }
    26         int ans=-1;
    27         for(int i=1;i<maxn;i++){
    28             dp[i]+=cnt[i];
    29             for(int j=i+i;j<maxn;j+=i){
    30                 dp[j]=max(dp[i],dp[j]);
    31             }
    32             ans=max(ans,dp[i]);
    33         }
    34         printf("%d
    ",n-ans);
    35     }
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    javaee 第六周作业
    javaee 第五周作业
    javaee 第四周作业
    第三周作业
    第二周作业xml学习情况
    javaWeb 中http请求 get 与 post的区别
    第八周
    第七周
    第六周
    第五周
  • 原文地址:https://www.cnblogs.com/noback-go/p/14339719.html
Copyright © 2011-2022 走看看