Codforces 401D

题目链接:CF 401D

本来以为是数位DP的题目,就直接套了模板,但是发现只用二进制来表示相应的位数已经被选过,选择的顺序并不能体现。

看了题解发现是想普通的dp那样定义,用dp【i】【j】表示集合i中的点已经被选择,%m结果为j的方案总数。

最后dp【1<<(len-1)】【0】就代表符合条件的方案数目

#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#define LL long long
#define mod 1000000007
#define inf 0x3f3f3f3f
#define sqr(a) (a)*(a)
#define For(i,m,n) for(int i=m;i<=n;i++)
#define Dor(i,n,m) for(int i=n;i>=m;i--)
#define lan(a,b) memset(a,b,sizeof(a))

using namespace std;
LL n,m;
LL dp[1<<18][110];
LL a[20];
LL num[10];
LL f[20];


int len(LL n)
{
    int p=0;
    while(n)
    {
        a[p++]=n%10;
        num[n%10]++;
        n/=10;
    }
    return p;
}

int main()
{
    while(~scanf("%lld%lld",&n,&m))
    {
        lan(num,0);
        lan(dp,0);
        int p=0;
        while(n)
        {
            a[p++]=n%10;
            num[n%10]++;
            n/=10;
        }
        sort(a,a+p);
        for(int i=0;i<p;i++)
            if(a[i])
                dp[1<<i][a[i]%m]=1;
        f[0]=1;
        For(i,1,p) f[i]=f[i-1]*i;
        for(int i=1;i<(1<<p);i++)
            for(int j=0;j<p;j++)
            {
                if(i&(1<<j))
                {
                    for(int k=0;k<m;k++)
                    {
                        dp[i][(k*10+a[j])%m]+=dp[i^(1<<j)][k];
                    }
                }

            }
        For(i,0,9)
        {
        dp[(1<<p)-1][0]/=f[num[i]];
        }
        printf("%lld\n",dp[(1<<p)-1][0]);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个示例代码,实现了类似Codeforces的Rank榜计分功能。该代码使用 TypeScript 编写,包含了比赛类型、每场比赛的加分规则、选手等级的计算方法等功能。 ```typescript // 定义比赛类型的枚举 enum ContestType { Div1 = "Div. 1", Div2 = "Div. 2", Div3 = "Div. 3", Div4 = "Div. 4", } // 定义选手等级的枚举 enum Rank { Newbie = 0, Pupil = 1, Specialist = 2, Expert = 3, CandidateMaster = 4, Master = 5, InternationalMaster = 6, Grandmaster = 7, InternationalGrandmaster = 8, } // 定义每道题目的加分规则 interface ProblemScoringRule { baseScore: number; // 基础分数 bonusScore: number; // 奖励分数 penalty: number; // 惩罚分数 } // 定义比赛的加分规则 interface ContestScoringRule { problems: Record<string, ProblemScoringRule>; // 每道题目的加分规则 penalty: number; // 惩罚分数 } // 定义选手 interface Contestant { username: string; // 用户名 rank: Rank; // 等级 rating: number; // 等级分 } // 定义一个比赛类 class Contest { private type: ContestType; // 比赛类型 private scoringRule: ContestScoringRule; // 加分规则 private contestants: Contestant[]; // 选手列表 constructor(type: ContestType, scoringRule: ContestScoringRule) { this.type = type; this.scoringRule = scoringRule; this.contestants = []; } // 添加选手 addContestant(contestant: Contestant) { this.contestants.push(contestant); } // 计算选手等级分 calculateRating(contestant: Contestant, place: number) { const { problems, penalty } = this.scoringRule; let score = 0; let penaltyTime = 0; for (const problemId in problems) { const problem = problems[problemId]; if (contestant[problemId]) { // 如果选手做出了这道题 score += problem.baseScore + (place - 1) * problem.bonusScore - contestant[problemId] * problem.penalty; penaltyTime += contestant[problemId]; } } contestant.rating += score + penalty * penaltyTime; } // 计算所有选手的等级分 calculateAllRatings() { // 按照得分从高到低排序 this.contestants.sort((a, b) => b.score - a.score); // 计算每个选手的等级分 for (let i = 0; i < this.contestants.length; i++) { this.calculateRating(this.contestants[i], i + 1); } // 按照等级分从高到低排序 this.contestants.sort((a, b) => b.rating - a.rating); // 更新每个选手的等级 for (let i = 0; i < this.contestants.length; i++) { const contestant = this.contestants[i]; if (contestant.rating >= 2400) { contestant.rank = Rank.InternationalGrandmaster; } else if (contestant.rating >= 2300) { contestant.rank = Rank.Grandmaster; } else if (contestant.rating >= 2100) { contestant.rank = Rank.InternationalMaster; } else if (contestant.rating >= 1900) { contestant.rank = Rank.Master; } else if (contestant.rating >= 1600) { contestant.rank = Rank.CandidateMaster; } else if (contestant.rating >= 1400) { contestant.rank = Rank.Expert; } else if (contestant.rating >= 1200) { contestant.rank = Rank.Specialist; } else if (contestant.rating >= 1000) { contestant.rank = Rank.Pupil; } else { contestant.rank = Rank.Newbie; } } } } ``` 以上是一个简单的实现,您可以根据实际需要进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值