Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大水题,都不用苯地debug就1A#include <iostream> #include <string.h> #include <stdio.h> #include <stdlib.h> using namespace std; char thresStr[10], paper[10]; int thres; int state; int mx; int len; int res[10]; int intv[11][11]; int resGs; bool init(){ scanf("%s%s", thresStr, paper); thres = atoi(thresStr); if(strcmp(paper, "0") == 0 && (!thres)){ return 0; } mx = -1; len = strlen(paper); state = 0; for(int i = 0; i < len; i++) intv[i][i] = 0; for(int j = 0; j < len; j++){ for(int i = j+1; i <= len; i++){ intv[j][i] = 10 * intv[j][i-1] + (paper[i-1]-'0'); } } return 1; } void solve(){ int p2len = 1 << (len-1); for(int istate = 0; istate < p2len; istate++){ int dbgs = 0; int dbPos[11]; for(int i = 0; i < len-1; i++){ if((istate >> i)%2 == 1){ dbPos[dbgs] = i; dbgs++; } } dbPos[dbgs] = len-1; dbgs++; int curPos = 0; int sum = 0; int tmpRes[11]; for(int i = 0; i < dbgs; i++){ sum += intv[curPos][dbPos[i]+1]; tmpRes[i] = intv[curPos][dbPos[i]+1]; curPos = dbPos[i]+1; } if(sum <= thres && sum > mx){ mx = sum; state = 0; resGs = dbgs; for(int i = 0; i < dbgs; i++){ res[i] = tmpRes[i]; } } else if(sum == mx){ state = 1; } } } int main() { while(init()){ solve(); if(mx == -1){ printf("error\n"); } else if(state == 1){ printf("rejected\n"); } else{ printf("%d", mx); for(int i = 0; i < resGs; i++){ printf(" %d", res[i]); } printf("\n"); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator