Download spoj_cpp_clean/ACMAKER/ACMAKER-3.cpp from slayone/uva_spoj_raw: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/ACMAKER/ACMAKER-3.cpp
- Command line
-
hf download hf://datasets/slayone/uva_spoj_raw/spoj_cpp_clean/ACMAKER/ACMAKER-3.cpp
-
curl -L -o ACMAKER-3.cpp https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/ACMAKER/ACMAKER-3.cpp
2.05 kB
| using namespace std; | |
| // Uglyyyyyyyyyyyy | |
| int main(){ | |
| int n, i, j, k, dp[151][151], count[151][151], w; | |
| count[0][0] = 1; | |
| for(i = 1; i <= 150; i++) | |
| count[0][i] = 0; | |
| for(i = 1; i <= 150; i++) | |
| count[i][0] = 1; | |
| string input, acronym, up_acronym, word; | |
| set<string> insig; | |
| vector<string> words; | |
| sd(n); | |
| while(n != 0){ | |
| insig.clear(); | |
| for(i = 0; i < n; i++){ | |
| cin>>word; | |
| insig.insert(word); | |
| } | |
| getline(cin,input); | |
| while(getline(cin,input) and input != "LAST CASE"){ | |
| words.clear(); | |
| stringstream ss; | |
| ss<<input; | |
| ss>>up_acronym; | |
| acronym = ""; | |
| for(i = 0; i < up_acronym.length(); i++) acronym += tolower(up_acronym[i]); | |
| while(ss>>word){ | |
| if(insig.find(word) == insig.end()){ | |
| words.push_back(word); | |
| } | |
| } | |
| int l1 = words.size(), l2 = acronym.length() ; | |
| for(i = 0; i <= l1; i++) | |
| for(j = 0; j <= l2; j++) | |
| dp[i][j] = 0; | |
| dp[0][0] = 1; | |
| for(i = 0; i < l1; i++){ | |
| for(j = 1; j <= l2; j++){ | |
| for(k = 1; k <= l2 - j + 1; k++){ | |
| for(int p = 1; p <= words[i].length(); p++){ | |
| for(int q = 1; q <= k; q++){ | |
| count[p][q] = count[p-1][q]; | |
| if(words[i][p-1] == acronym[j+q-2]) count[p][q] += count[p-1][q-1]; | |
| } | |
| } | |
| w = count[words[i].length()][k]; | |
| dp[i+1][j+k-1] += w * dp[i][j-1]; | |
| } | |
| } | |
| } | |
| if(dp[l1][l2]){ | |
| cout<<up_acronym<<" can be formed in "<<dp[l1][l2]<<" ways"<<endl; | |
| } | |
| else{ | |
| cout<<up_acronym<<" is not a valid abbreviation"<<endl; | |
| } | |
| } | |
| sd(n); | |
| } | |
| return 0; | |
| } | |