求问
  • 板块学术版
  • 楼主Besheep
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/11/25 19:03
  • 上次更新2024/11/25 20:39:07
查看原帖
求问
1186526
Besheep楼主2024/11/25 19:03

对于下面暴力程序,当 n>kn>k 时,T n kT\ n\ k 为何值时,能卡掉下面的暴力代码(正解为 O(Tn)O(Tn) 的复杂度)。

#include <bits/stdc++.h>
using namespace std;
int T,n,k,a[100010],ans;
string s;
int main() {
    cin>>T;
    while(T--){
    	ans=0;
    	cin>>n>>k>>s;
    	for(int i=0;i<=n-k;i++){
    		for(int j=0;j<k;j++){
    			if(s[i+j]=='1'){
    				ans++;
    				break;
				}
			}
		}
    	cout<<ans<<endl;
	}
    
	return 0;
}
2024/11/25 19:03
加载中...