UVA 11552 Fewest Flops
来源:互联网 发布:可以免费开淘宝店吗 编辑:程序博客网 时间:2024/06/09 13:45
水题
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#define MAX 1100using namespace std;char s[MAX];int L,k,dp[MAX][26],count_t[26];void init(){cin>>k;cin>>s;L=strlen(s);memset(dp,0x7f,sizeof(dp));}void solve(){for(int i=0;i<L/k;i++){int front=i*k,rear=(i+1)*k-1;memset(count_t,0,sizeof(count_t));for(int j=front;j<=rear;j++)count_t[s[j]-'a']++;int kind=0;for(int j=0;j<26;j++)if(count_t[j])kind++;for(int j=0;j<26;j++){if(count_t[j]){if(i==0)dp[i][j]=kind;else{for(int t=0;t<26;t++){if(j!=t){if(count_t[t])dp[i][j]=min(dp[i][j],dp[i-1][t]+kind-1);elsedp[i][j]=min(dp[i][j],dp[i-1][t]+kind);}else{if(kind==1)dp[i][j]=min(dp[i][j],dp[i-1][t]);elsedp[i][j]=min(dp[i][j],dp[i-1][t]+kind);}}}}}}int ans=0x7f7f7f7f;for(int i=0;i<26;i++){ans=min(ans,dp[L/k-1][i]);}cout<<ans<<endl;}int main(){int T;cin>>T;while(T--){init();solve();}return 0;}
0 0
- UVA 11552 Fewest Flops
- uva 11552 Fewest Flops
- UVA 11552 Fewest Flops
- UVA 11552 Fewest Flops
- UVA - 11552 Fewest Flops
- UVa:11552 - Fewest Flops
- UVA 11552 Fewest Flops
- uva 11552 Fewest Flops
- UVA 11552 Fewest Flops
- Uva 11552 Fewest Flops
- UVA 11552 Fewest Flops
- uva 11552 - Fewest Flops(dp)
- UVA 11552 Fewest Flops(DP)
- FEWEST FLOPS - UVa 11552 dp
- UVA - 11552 Fewest Flops DP
- uva 11552 - Fewest Flops(dp)
- Uva 11552 Fewest Flops (三维动态规划)
- Uva 11552 - Fewest Flops 字符串dp
- 类加载器
- cocos2d-x lua调用c++函数
- asp生成xml文件
- RequireJS入门(一)
- Java基础——对象和类,类中的变量和方法
- UVA 11552 Fewest Flops
- Mac下eclipse环境配置问题集锦
- PopupWindow弹出时底层变暗(像Dialog弹出时的效果)
- js 语法
- jsp的静态引入和动态引入
- Linux命令简介—less
- Math类中提供了三个与取整有关的方法:ceil、floor、round
- RPG Maker MV之本地服务器搭建
- mysql截取函数