P3624 [APIO2008]DNA 后缀和优化DP

题意:

我们给定一组DNA序列(只含ACGT),其中部分位置用N表示为一个不确定的核苷酸,我们规定范式-X,表示按照字典序下降次数不超过x的DNA序列,给定一个长M的未确定DNA序列,输出将序列确定下来后范式-K中第R大的序列

范围&性质:

1 ≤ M ≤ 5 × 1 0 4 , 1 ≤ K ≤ 10 , 1 ≤ R ≤ 2 × 1 0 12 1\le M\le 5\times10^4,1\le K\le 10,1\le R\le 2\times 10^{12} 1M5×104,1K10,1R2×1012,保证未完成序列在范式-K形式下总数不超过 4 × 1 0 18 4\times10^{18} 4×1018

分析:

f [ i ] [ j ] [ k ] f[i][j][k] f[i][j][k]表示从 i i i往后划分成 j j j段,第 i i i个位置是 k k k的方案数,从后向前转移统计后缀的影响,然后按位枚举,枚举含 N N N的位置填什么,使方案数恰好等于 R R R时输出

代码:

#include<bits/stdc++.h>

using namespace std;

namespace zzc
{
    typedef long long ll; 
	const int maxn = 5e4+5;
	ll m,k,r;
	ll nw[maxn],f[maxn][20][5];
	map<char,ll> s;
	char ch[maxn];

	void work()
	{
		s['A']=1;s['C']=2;s['G']=3;s['T']=4;s['N']=0;
		scanf("%lld%lld%lld",&m,&k,&r);
		scanf("%s",ch+1);
		for(ll i=1;i<=m;i++) nw[i]=s[ch[i]];
		if(nw[m]) f[m][1][nw[m]]=1;
		else
		{
			for(int i=1;i<=4;i++) f[m][1][i]=1;
		}
		for(int i=m-1;i>=1;i--)
		{
			for(int x=1;x<=4;x++)
			{
				if(!nw[i]||nw[i]==x)
				{
					for(int j=1;j<=k;j++)
					{
						for(int y=1;y<=4;y++)
						{
							f[i][j][x]+=f[i+1][j-(x>y)][y];
						}
					}
				}
			}
		}
		for(int i=1;i<=m;i++)
		{
			for(int j=1;j<=k;j++)
			{
				for(int x=1;x<=4;x++)
				{
					f[i][j][x]+=f[i][j-1][x];
				}
			}
		}
		int lst=0;
		for(int i=1;i<=m;i++)
		{
			if(nw[i])
			{
				printf("%c",ch[i]);
				k-=(nw[i]<lst);
				lst=nw[i];
			}
			else
			{
				int now=1;
				while(now<=4&&r>f[i][k-(now<lst)][now])
				{
					r-=f[i][k-(now<lst)][now];
					now++;
				}
				k-=(now<lst);
				if(now==1) printf("A");
				else if(now==2) printf("C");
				else if(now==3) printf("G");
				else if(now==4) printf("T");
				lst=now;
			}
		}
	}

}

int main()
{
	zzc::work();
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值