CF981D Bookshelves

传送门

这居然是个*1800的题,有点无法接受,可能自己\(dp\)方面确实差了点
考虑按位\(dp\),从高位到低位枚举,然后用\(dp\)去判断是否可行。
然后设\(f[i][j]\)表示前\(i\)个分成\(j\)块能否满足当前枚举的答案
代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
void read(int &x) {
    char ch; bool ok;
    for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
    for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=60;
int n,k,f[maxn][maxn];long long a[maxn],ans;
bool dp(long long ans)
{
    memset(f,0,sizeof f);f[0][0]=1;
    for(rg int i=1;i<=n;i++)
        for(rg int j=0;j<i;j++)
            for(rg int k=j;k<i;k++)
                if(((a[i]-a[k])&ans)==ans)f[i][j+1]|=f[k][j];
    return f[n][k];
}
int main()
{
    read(n),read(k);
    for(rg int i=1;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1];
    for(rg int i=60;i>=0;i--)if(dp(ans|(1ll<<i)))ans|=1ll<<i;
    printf("%lld\n",ans);
}

转载于:https://www.cnblogs.com/lcxer/p/10639236.html

38.He took his umbrella ______ it should rain.(2分) A in case of B in case C for fear D in time 39.Not until this term ( ) to realize how important this subject is to his future career as a diplomat.(2分) A he began B did he begin C he has begun D that he has begun 40.Great changes ______ in Shanghai since the beginning of the reform and opening-up policy.(2分) A took place B has taken place C has been taken place D have taken place 41.The larger the house is, ______.(2分) A the higher rent it is B the higher rent it would have C the higher the rent is D the higher rent it would be 42.Every time Jane has trouble ______ her car started, Sean will show up to lend a hand.(2分) A get B getting C to getting D to get44.Some bookshelves have been moved out of this office to make ______ for more computers.(2分) A space B place C room D position46. Wendy: Have you been to the new bakery on the corner? Arthur: NO, how is it? Wendy: It is heaven!________! (2分) A Their cakes are to strive for B Their cakes are to pay for C Their cakes are to struggle for D Their cakes are to die for 47.Dr. Jones, many students want to see you.( ) they wait here or outside?(2分) A Do B Will C Shall D Would 48.( ) who would like to go on the trip should put their names on the list. (2分) A Those B These C Somebody D The ones 49. Kate: Do you mind opening the door for me? Bob: _________. (2分) A It’s nothing B That’s all right C Yes, I’ll do it D Not at all 50.They first stop at a board _____ the menu is displayed.(2分) A when B while C where D which
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值