这篇教程C++ DP函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中DP函数的典型用法代码示例。如果您正苦于以下问题:C++ DP函数的具体用法?C++ DP怎么用?C++ DP使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了DP函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: minDistance int minDistance(string word1, string word2) { vector<vector<int>> DP(word1.size()+1, vector<int> (word2.size()+1, 0)); for(int i = 1; i<=word1.size(); i++) { DP[i][0] = i; } for(int j = 1; j <= word2.size(); j++) { DP[0][j] = j; } for(int i = 1; i<=word1.size(); i++) { for(int j=1; j<=word2.size(); j++) { if(word1[i-1] == word2[j-1]) { DP[i][j] = DP[i-1][j-1]; } else { DP[i][j] = min(min(DP[i-1][j] + 1, DP[i][j-1] + 1), DP[i-1][j-1] + 1); } } } return DP[word1.size()][word2.size()]; }
开发者ID:YuxuanHe,项目名称:Leetcode,代码行数:20,
示例2: __addip/* returns 0 on success */static inline int__addip(struct ip_set *set, ip_set_ip_t ip, unsigned char *ethernet, ip_set_ip_t *hash_ip){ struct ip_set_macipmap *map = (struct ip_set_macipmap *) set->data; struct ip_set_macip *table = (struct ip_set_macip *) map->members; if (ip < map->first_ip || ip > map->last_ip) return -ERANGE; if (test_and_set_bit(IPSET_MACIP_ISSET, &table[ip - map->first_ip].flags)) return -EEXIST; *hash_ip = ip; DP("%u.%u.%u.%u, %u.%u.%u.%u", HIPQUAD(ip), HIPQUAD(*hash_ip)); memcpy(&table[ip - map->first_ip].ethernet, ethernet, ETH_ALEN); return 0;}
开发者ID:cilynx,项目名称:dd-wrt,代码行数:21,
示例3: setpoolstatic int setpool( struct sock *sk, int optval, void *user, unsigned int len) { struct ip_pool_request req; DP("ip_pool:setpool: optval=%d, user=%p, len=%d/n", optval, user, len); if (!capable(CAP_NET_ADMIN)) return -EPERM; if (optval != SO_IP_POOL) return -EBADF; if (len != sizeof(req)) return -EINVAL; if (copy_from_user(&req, user, sizeof(req)) != 0) return -EFAULT; printk("obsolete op - upgrade your ippool(8) utility./n"); return -EINVAL;}
开发者ID:JBTech,项目名称:ralink_rt5350,代码行数:20,
示例4: DPvoid CSVPHostMountCB::FileOpenL(const TDesC& aName,TUint aMode,TFileOpen anOpen,CFileCB* aFile) { DP(_L("** (SVPHOSTMNT) CSVPHostMountCB::FileOpenL(%S)"), &aName); CSVPHostFileCB& file=(*((CSVPHostFileCB*)aFile)); TBuf<KMaxPath> name; TUint driveNumber = Drive().DriveNumber(); CanonicalizePathname(aName, driveNumber, name); TSVPHostFsFileOpenInfo info(driveNumber, name,aMode,anOpen); TInt err = SVP_HOST_FS_DEVICE().FileOpen(info); User::LeaveIfError(err); file.SetHandle(info.iHandle); file.SetSize(info.iSize); file.SetAtt(info.iAtt&KEntryAttMaskSupported); TTime tempTime=file.Modified(); fileTimeToTime(info.iModified, tempTime, info.iTimeType); file.SetModified(tempTime); }
开发者ID:SymbianSource,项目名称:oss.FCL.interim.QEMU,代码行数:20,
示例5: sizeofwyToast* wyToast::make(const char* text, float duration) { // create texture of default toast background wyTexture2D* bgTex = wyTexture2D::makeRawPNG((const char*)_toast_bg_png, sizeof(_toast_bg_png) - 2); wyNinePatchSprite* bg = wyNinePatchSprite::make(bgTex, wyr(DP(24), DP(24), 1, 1)); // create label as content wyLabel* label = wyLabel::make(text, SP(12), BOLD); label->setLineWidth(wyDevice::winWidth * 4 / 5); // create toast and set default margin wyToast* t = WYNEW wyToast(bg, label, duration); t->setMargin(DP(15), DP(20), DP(20), DP(15)); t->m_useDefaultBg = true; return (wyToast*)t->autoRelease();}
开发者ID:barroque,项目名称:WiEngine,代码行数:15,
示例6: i2c_select_devicestatic uchar i2c_select_device (uchar dev_addr, uchar read, int ten_bit){ unsigned int status, data, bits = 7; int count = 0; DP (puts ("i2c_select_device/n")); /* Output slave address */ if (ten_bit) { bits = 10; } data = (dev_addr << 1); /* set the read bit */ data |= read; GT_REG_WRITE (I2C_DATA, data); /* assert the address */ RESET_REG_BITS (I2C_CONTROL, BIT3); udelay (I2C_DELAY); GT_REG_READ (I2C_STATUS_BAUDE_RATE, &status); count = 0; while (((status & 0xff) != 0x40) && ((status & 0xff) != 0x18)) { udelay (I2C_DELAY); if (count > 20) { GT_REG_WRITE (I2C_CONTROL, (0x1 << 4)); /*stop */ return (status); } GT_REG_READ (I2C_STATUS_BAUDE_RATE, &status); count++; } if (bits == 10) { printf ("10 bit I2C addressing not yet implemented/n"); return (0xff); } return (0);}
开发者ID:12019,项目名称:u-boot-2009.07-silvermoon,代码行数:41,
示例7: i2c_write/* anything but zero is failure */uchari2c_write (uchar dev_addr, unsigned int offset, int alen, uchar * data, int len){ uchar status = 0; unsigned int i2cFreq = CONFIG_SYS_I2C_SPEED; DP (puts ("i2c_write/n")); i2c_init (i2cFreq, 0); /* set the i2c frequency */ status = i2c_start (); /* send a start bit */ if (status) {#ifdef DEBUG_I2C printf ("Transaction start failed: 0x%02x/n", status);#endif return status; } status = i2c_set_dev_offset (dev_addr, offset, 0, alen); /* send the slave address + offset */ if (status) {#ifdef DEBUG_I2C printf ("Failed to set slave address & offset: 0x%02x/n", status);#endif return status; } status = i2c_write_byte (data, len); /* write the data */ if (status) {#ifdef DEBUG_I2C printf ("Data not written: 0x%02x/n", status);#endif return status; } /* issue a stop bit */ i2c_stop (); return 0;}
开发者ID:12019,项目名称:u-boot-2009.07-silvermoon,代码行数:42,
示例8: hash_id_cidrstatic inline __u32hash_id_cidr(struct ip_set_nethash *map, ip_set_ip_t ip, unsigned char cidr, ip_set_ip_t *hash_ip){ __u32 id; u_int16_t i; ip_set_ip_t *elem; *hash_ip = pack(ip, cidr); for (i = 0; i < map->probes; i++) { id = jhash_ip(map, i, *hash_ip) % map->hashsize; DP("hash key: %u", id); elem = HARRAY_ELEM(map->members, ip_set_ip_t *, id); if (*elem == *hash_ip) return id; } return UINT_MAX;}
开发者ID:inibir,项目名称:daemongroup,代码行数:21,
示例9: adt_parser/* Add, del, test parser */static ip_set_ip_tadt_parser(unsigned cmd, const char *optarg, void *data){ struct ip_set_req_macipmap *mydata = (struct ip_set_req_macipmap *) data; char *saved = ipset_strdup(optarg); char *ptr, *tmp = saved; DP("macipmap: %p %p", optarg, data); ptr = strsep(&tmp, ":%"); parse_ip(ptr, &mydata->ip); if (tmp) parse_mac(tmp, mydata->ethernet); else memset(mydata->ethernet, 0, ETH_ALEN); free(saved); return 1; }
开发者ID:inibir,项目名称:daemongroup,代码行数:22,
示例10: run_com_generalint run_com_general(const char *buffer) { int scan_count; scan_count = sscanf(buffer, PROC_STRING, PROC_SCANF_LIST); if( scan_count != LIST_LEN) { printk("eth proc bad format %x != %x/n", scan_count, LIST_LEN ); return 1; }#ifndef INCLUDE_MULTI_QUEUE printk("/n Be carefull eth is compiled without MULTI Q!! /n");#endif switch(command){ case COM_SRQ: DP(" Port %x: Got SRQ command Q %x and packet type is %x <bpdu/arp/tcp/udp> /n",port,q,packett); run_com_srq(); break; case COM_SQ: DP(" Port %x: Got SQ command Q %x direction %x <Rx/Tx> mac %2x:%2x:%2x:%2x:%2x:%2x/n",port, q, direct, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); run_com_sq(); break;#ifdef INCLUDE_MULTI_QUEUE case COM_SRP: DP(" Port %x: Got SRP command Q %x policy %x <Fixed/WRR> /n",port,q,policy); run_com_srp(); break; case COM_SRQW: DP(" Port %x: Got SQRW command Q %x weight %x /n",port,q,weight); run_com_srqw(); break; case COM_STP: DP("STP cmd - Unsupported: Port %x Q %x policy %x <WRR/FIXED> weight %x/n",port,q,policy,weight); break;#endif /* INCLUDE_MULTI_QUEUE */ case COM_STS: DP(" Port %x: Got STS command status %x/n",port,status); run_com_statis(); break; default: printk("eth proc unknown command./n"); } return 0;}
开发者ID:robacklin,项目名称:ts7800,代码行数:48,
示例11: minCut int minCut(string s) { int slen = s.length (); if (slen < 2) return 0; dp.resize (slen); for (int i=0;i<slen;i++) dp[i].resize (0); for (int i=0;i<slen;i++){ int low = i, high = i+1; while (low>=0 && high<slen && s[low]==s[high]){ dp[high].push_back (low); low--, high++; } dp[i].push_back (i); low = i-1, high = i + 1; while (low>=0 && high<slen && s[low]==s[high]) dp[high].push_back (low),low--, high++; } f.resize (slen+1); fill_n (f.begin(), slen+1, -1); f[0] = 0; return DP(slen) - 1; }
开发者ID:ivanzjj,项目名称:Leetcode,代码行数:21,
示例12: knh_HashMap__kvoid knh_HashMap__k(Ctx *ctx, knh_Hash_t *o, OutputStream *w, String *m){ size_t pos = 0, c = 0; size_t max = (KNH_HASH_TABLESIZE / o->hashop->size) * DP(o)->tables_size; knh_putc(ctx, w, '{'); while(pos < max) { knh_hashentry_t *e = knh_hashentry_at((knh_Hash_t*)o, pos); if(e != NULL) { if(c > 0) { knh_write_delim(ctx,w); } knh_format(ctx, w, METHODN__k, e->key, KNH_NULL); knh_putc(ctx, w, ':'); knh_putc(ctx, w, ' '); knh_format(ctx, w, METHODN__k, e->value, KNH_NULL); c++; } pos++; } knh_putc(ctx, w, '}');}
开发者ID:matsuu,项目名称:konoha,代码行数:21,
示例13: i2c_probe/* anything other than zero is failure, no device */int i2c_probe (uchar chip){ /* We are just looking for an <ACK> back. */ /* To see if the device/chip is there */#ifdef DEBUG_I2C unsigned int i2c_status;#endif uchar status = 0; unsigned int i2cFreq = CONFIG_SYS_I2C_SPEED; DP (puts ("i2c_probe/n")); i2c_init (i2cFreq, 0); /* set the i2c frequency */ status = i2c_start (); /* send a start bit */ if (status) {#ifdef DEBUG_I2C printf ("Transaction start failed: 0x%02x/n", status);#endif return (int) status; } status = i2c_set_dev_offset (chip, 0, 0, 0); /* send the slave address + no offset */ if (status) {#ifdef DEBUG_I2C printf ("Failed to set slave address: 0x%02x/n", status);#endif return (int) status; }#ifdef DEBUG_I2C GT_REG_READ (I2C_STATUS_BAUDE_RATE, &i2c_status); printf ("address %#x returned %#x/n", chip, i2c_status);#endif /* issue a stop bit */ i2c_stop (); return 0; /* successful completion */}
开发者ID:12019,项目名称:u-boot-2009.07-silvermoon,代码行数:41,
示例14: html_head// Create a new HTML file with a given filename and title// The heading, if not given, will be the same as the titlevoidhtml_head(FILE *of, const string fname, const string title, const char *heading){ swill_title(title.c_str()); if (DP()) cerr << "Write to " << fname << endl; fprintf(of, "<!doctype html public /"-//IETF//DTD HTML//EN/">/n" "<html>/n" "<head>/n" "<meta name=/"GENERATOR/" content=/"CScout %s - %s/">/n", Version::get_revision().c_str(), Version::get_date().c_str()); fputs( "<meta http-equiv=/"Content-Style-Type/" content=/"text/css/">" "<style type=/"text/css/" >" "<!--/n", of); ifstream in; string css_fname; if (cscout_input_file("style.css", in, css_fname)) { int val; while ((val = in.get()) != EOF) putc(val, of); } else fputs(#include "css.c" , of); fputs( "-->" "</style>" "</head>", of); fprintf(of, "<title>%s</title>/n" "</head>/n" "<body>/n" "<h1>%s</h1>/n", title.c_str(), heading ? heading : title.c_str());}
开发者ID:damorinCan,项目名称:cscout,代码行数:42,
示例15: i2c_writeint i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len){ MV_TWSI_SLAVE twsiSlave; DP(puts("i2c_write/n")); twsiSlave.slaveAddr.type = ADDR7_BIT; twsiSlave.slaveAddr.address = chip; if(alen != 0){ twsiSlave.validOffset = MV_TRUE; twsiSlave.offset = addr; if(alen == 2) { twsiSlave.moreThen256 = MV_TRUE; } else { twsiSlave.moreThen256 = MV_FALSE; } } i2c_init(CONFIG_SYS_I2C_SPEED,0); /* set the i2c frequency */ return mvTwsiWrite (i2c_current_bus, &twsiSlave, buffer, len);}
开发者ID:12thmantec,项目名称:u-boot-novena-spl,代码行数:22,
示例16: sqlite3_execstaticknh_dbcur_t *knh_dbquery__sqlite3(Ctx *ctx, knh_db_t *hdr, knh_bytes_t sql, ResultSet *rs){ if(rs == NULL) { int r = sqlite3_exec((sqlite3*)hdr, (const char*)sql.buf, NULL, NULL, NULL); if(r != SQLITE_OK) { knh_sqlite3_perror(ctx, (sqlite3*)hdr, r); } return NULL; } else { sqlite3_stmt *stmt = NULL; sqlite3_prepare((sqlite3*)hdr, (char*)sql.buf, sql.len, &stmt, NULL);// if (r != SQLITE_OK) {// sqlite3_finalize(stmt);// DBG2_P("msg='%s', sqlite3_errmsg((sqlite3)hdr));// return NULL;// }// r = sqlite3_reset(stmt);// if(r != SQLITE_OK) {// sqlite3_finalize(stmt);// return NULL;// } size_t column_size = (size_t)sqlite3_column_count(stmt); //DBG2_P("column_size=%d", column_size); knh_ResultSet_initColumn(ctx, rs, column_size); if(column_size > 0) { size_t i; for(i = 0; i < DP(rs)->column_size; i++) { char *n = (char*)sqlite3_column_name(stmt, i); //DBG2_P("(%d) name = '%s'", i, n); if(n != NULL) { knh_ResultSet_setName(ctx, rs, i, new_String(ctx, B(n), NULL)); } } } return (knh_dbcur_t*)stmt; }}
开发者ID:matsuu,项目名称:konoha,代码行数:39,
示例17: knh_cwb_openstatic knh_String_t *Gamma_vperror(CTX ctx, int pe, const char *fmt, va_list ap){ knh_String_t *msg = TS_EMPTY; int isPRINT = (pe <= KC_DWARN) ? 1 : 0; if(pe != KC_DEBUG && (CTX_isInteractive(ctx) || knh_isCompileOnly(ctx))) { isPRINT = 1; } if(Gamma_isQuiet(ctx->gma) || ctx->gma->uline == 0) { isPRINT = 0; } //DBG_P("/*isPRINT=%d*/ uline=%d", isPRINT, ctx->gma->uline); if(isPRINT == 1) { knh_cwb_t cwbbuf, *cwb = knh_cwb_open(ctx, &cwbbuf); knh_write_uline(ctx, cwb->w, ctx->gma->uline); knh_write_ascii(ctx, cwb->w, KC__(pe)); knh_vprintf(ctx, cwb->w, fmt, ap); msg = knh_cwb_newString(ctx, cwb); knh_Array_add(ctx, DP(ctx->gma)->errmsgs, msg); fprintf(stderr, "%s - %s%s/n", TERM_BNOTE(ctx, pe), S_tochar(msg), TERM_ENOTE(ctx, pe)); } return msg;}
开发者ID:shinpei,项目名称:konoha-wand,代码行数:22,
示例18: kSum2 /** * @param A: an integer array. * @param k: a positive integer (k <= length(A)) * @param target: a integer * @return an integer */ int kSum2(vector<int> A, int k, int target) { int n = A.size(); // DP[i][j][t] means the total number of combinations that j numbers out of first A[0~i-1] sum up to t vector<vector<vector<int> > > DP(n+1, vector<vector<int> >(k+1, vector<int>(target+1, 0))); for (int i = 0; i <= A.size(); i++) { DP[i][0][0] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= min(k,i); j++) { for (int t = 1; t < A[i-1]; t++) { DP[i][j][t] = DP[i-1][j][t]; } for (int t = A[i-1]; t <= target; t++) { DP[i][j][t] = DP[i-1][j][t] + DP[i-1][j-1][t-A[i-1]]; } } } return DP[n][k][target]; }
开发者ID:pmdiano,项目名称:shuati,代码行数:28,
示例19: DPSTDMETHODIMP CGfxFB::Open(DWORD dwWidth, DWORD dwHeight, DWORD dwBuffers, const DWORD *pdwFourCC, IMcPreInit* pPrepareData, RECT* pDst) { POINT pt; if(dwWidth==0 || dwHeight==0) return E_FAIL; m_dwWidth = dwWidth; m_dwHeight = dwHeight; if(pdwFourCC) m_pdwFourCCList = pdwFourCC; else m_pdwFourCCList = const_dwFourCC; DP("[GFXFB]Open w:%d h:%d /n",m_dwWidth, m_dwHeight); pt.x = m_rectDst.left; pt.y = m_rectDst.top; m_bScnClip = TRUE; return CreateSurfaces(dwBuffers);}
开发者ID:xuweiqiang,项目名称:LibVRPresent,代码行数:22,
示例20: knh_Stmt__svoid knh_Stmt__s(Ctx *ctx, Stmt *o, OutputStream *w, String *m){ knh_intptr_t i; knh_putc(ctx, w, '('); if(SP(o)->stt != STT_OP && SP(o)->stt != STT_NEW && SP(o)->stt != STT_CALL ) { knh_write_char(ctx, w, knh_stmt_tochar(SP(o)->stt)); if(DP(o)->size > 0) { knh_putc(ctx, w, ' '); } } for(i = 0; i < DP(o)->size; i++) { if(i > 0) knh_putc(ctx, w, ' '); if(IS_Token(DP(o)->terms[i])) { knh_Token__s(ctx, DP(o)->tokens[i], w, m); } else { KNH_ASSERT(IS_Stmt(DP(o)->terms[i])); knh_Stmt__s(ctx, DP(o)->stmts[i], w, m); if(IS_NOTNULL(DP(DP(o)->stmts[i])->next)) { knh_write_dots(ctx, w); } } } knh_putc(ctx, w, ')');}
开发者ID:matsuu,项目名称:konoha,代码行数:24,
示例21: numDecodings int numDecodings(string s) { if(s.empty())return 0; if(s.size()==1 && s[0]=='0') return 0; vector<int>DP(s.size()+1,1); for(int i=2; i<=s.size();i++){ int cur = s[i-1] - '0'; int pre = s[i-2] - '0'; if((pre==0 && i==2) || (cur==0 && (pre>2 || pre==0))) return 0; if( (pre==2 && cur<=6 && cur>0) || (pre==1 && cur<=9 && cur>0) ) { if(i<s.size() && s[i]=='0'){ DP[i] = DP[i-1]; }else DP[i] = DP[i-1] + DP[i-2]; } else{ DP[i] = DP[i-1]; } } return DP[s.size()]; }
开发者ID:AhmadSamih,项目名称:Brain-Teasers-Data-Structures-Algorithms,代码行数:23,
示例22: run_com_generalint run_com_general(const char *buffer) { int scan_count; scan_count = sscanf(buffer, PROC_STRING, PROC_SCANF_LIST); if( scan_count != LIST_LEN) { printk("eth proc bad format %x != %x/n", scan_count, LIST_LEN ); return 1; } switch(command){ case COM_SRQ: DP(" Port %x: Got SRQ command Q %x and packet type is %x <bpdu/arp/tcp/udp> /n",port,q,packet); run_com_srq(); break; case COM_SQ: DP(" Port %x: Got SQ command Q %x mac %2x:%2x:%2x:%2x:%2x:%2x/n",port, q, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); run_com_sq(); break;#if (MV_ETH_RX_Q_NUM > 1) case COM_SRP: DP(" Port %x: Got SRP command Q %x policy %x <Fixed/WRR> /n",port,q,policy); printk("Not supported/n"); break; case COM_SRQW: DP(" Port %x: Got SQRW command Q %x weight %x /n",port,q,weight); printk("Not supported/n"); break; case COM_STP: DP("STP cmd - Unsupported: Port %x Q %x policy %x <WRR/FIXED> weight %x/n",port,q,policy,weight); break;#endif /* MV_ETH_RX_Q_NUM > 1 */ case COM_STS: DP(" Port %x: Got STS command status %x/n",port,status); run_com_stats(); break; default: printk("eth proc unknown command./n"); } return 0;}
开发者ID:HuxyUK,项目名称:xpenology-3.x,代码行数:45,
|