Hdu 5496 Beauty of Sequence (组合数)
生活随笔
收集整理的這篇文章主要介紹了
Hdu 5496 Beauty of Sequence (组合数)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:
Hdu 5496 Beauty of Sequence
題目描述:
一個整數序列,除去連續的相同數字(保留一個)后,序列的和成為完美序列和。問:一個整數序列的所有子序列的完美序列和?
解題思路:
考慮位于i位置數字x的貢獻值,假設x是子序列中連續相同數字的第一個,那么x對于i后面的數有2(n-i)個貢獻值,對前面的數,要么不選取,要么選取結尾不為x的方案數目。
#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
const LL maxn = ;
const LL mod = ;
LL a[maxn];
map<LL, LL>M; int main ()
{
LL t, n;
scanf ("%lld", &t); while (t --)
{
scanf ("%lld", &n);
for (int i=; i<n; i++)
scanf ("%lld", &a[i]); LL sum, cnt, num;
sum = cnt = ;
M.clear(); for (int i=; i<n; i++)
{
num = (cnt + - M[a[i]] + mod) % mod;
sum = ( * sum % mod + num * a[i] % mod) % mod;
M[a[i]] = (M[a[i]] + cnt + ) % mod;
cnt = (cnt * + ) % mod;
} printf ("%lld\n", sum);
}
return ;
}
總結
以上是生活随笔為你收集整理的Hdu 5496 Beauty of Sequence (组合数)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NPOI在EXCEL中插入图片和超链接
- 下一篇: List去除重复数据的五种方式