kamacoder-solutions icon indicating copy to clipboard operation
kamacoder-solutions copied to clipboard

第28题:子序列中的 k 种字母,测试案例test7的结果一定会超出范围

Open Sauce-amide opened this issue 1 year ago • 6 comments

只有对中间相乘结果超过long long 范围的都对10^9+7取余,相加时候保存为int,才能和正确答案匹配,这感觉不符合题意,应该增加限制条件。

Sauce-amide avatar Aug 11 '23 04:08 Sauce-amide

这题等于k后剪枝的思路是什么。。。没看明白

grdiv avatar Aug 11 '23 06:08 grdiv

这题等于k后剪枝的思路是什么。。。没看明白

@grdiv 回溯法,在路径里字符种类等于k后,就开始计算每种字符有多少个子序列(2^n-1个),然后路径里的每种字符的子序列数相乘,就是刚好k种字母的子序列情况之和,这个分支就可以加进result里,再回溯找另外的情况。这里个题解里没有剪枝

我的issue就是这里在test7的测试用例中计算2^n-1会溢出,为了不溢出就需要取模10^9+7(从题解里看到的),才能得到用例给的正确输出。至于为什么是10^9+7而不是10^9+9之类的别的质数,我觉得应该作为题目条件加到题目条件里,不然AC不了。

Sauce-amide avatar Aug 11 '23 07:08 Sauce-amide

子序列个数会比较大,后台的测试数据是对10^9+7进行取模之后的答案。在题目描述里面需要添加一个提示。

charon2121 avatar Aug 12 '23 07:08 charon2121

收到反馈🌹,已添加提示

youngyangyang04 avatar Aug 13 '23 02:08 youngyangyang04

The answer to test case 7 is also not correct. Additionally, there's a bug in the solution for Q28, the res at this line overflows for test case 7 (validated on the platform) because it's not mod by 10^9+7.

mengdiwang avatar Aug 22 '23 05:08 mengdiwang

@mengdiwang I have the same doubt as well. Did you find a solution for it?

hhc99 avatar Sep 14 '23 11:09 hhc99